skip to Main Content

I try to change title on Archive page because i use it to list custom article type. In fact, i want to remove "Archive " text at the start of page title.

I use wordpress 5.8 and a custom theme from twenty twenty.

In my header.php file, there is that :

<?php wp_head(); ?>

But when i write the code below into my functions.php, nothing happens.

remove_action('wp_head', '_wp_render_title_tag');

I have also try to use filter but i don’t use it properly because nothing happens too.

How can i do that ?

Thanks !

3

Answers


  1. Chosen as BEST ANSWER

    Thanks @HowardE & @DeanTwit but i think my template have a problem beacause when i write : echo "i am here" into the functions, nothing happens.

    I have write your code at the end of functions.php.

    Is there a manipulation to be performed to run this process ?


  2. This one should do the trick :

     function change_archive_page_title( $title ) {
            if ( is_category() ) {
                $title = single_cat_title( '', false );
            } 
            return $title;
        }
         
        add_filter( 'get_the_archive_title', 'change_archive_page_title' );
    

    Add it to your child theme -> functions.php
    Edit: It replace the page title with empty string.

    Login or Signup to reply.
  3. To change the Archive Title, there are a few ways. One is probably using an SEO plugin? But to do it programmatically, you can use the filter get_the_archive_title

    Change your_taxonomy to the name of the taxonomy you want to modify what is displayed.

    add_filter( 'get_the_archive_title', 'custom_archive_title', 10, 3 );
    /**
     * Change the archive title for a custom taxonomy
     * 
     * @param string $title - The full archive Title
     * @param string $original_title - The name of the archive without prefix.
     * @param string $prefix - Prefix if set - otherwise "Archive"
     * @return mixed
     */
    function custom_archive_title( $title, $original_title, $prefix ) {
        // Get the queried object - which would be the WP_Term.
        $queried_object = get_queried_object();
        // Check if it's your custom taxonomy
        if ( 'your_taxonomy' === $queried_object->taxonomy ) {
            // Remove the prefix.
            $title = $original_title;
        }
        return $title;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search