skip to Main Content

I need to change the page title of this page. I created this page from the category. So the page title is showing the category name. I need to change that page title to News.

I couldn’t find an option or setting to change the title so need to change the title by using custom CSS.

enter image description here

This is what I see when I check the coding of the page:

enter image description here

Please help me change the page name to News instead of Category: News

2

Answers


  1. Place this code in your functions.php file

    function change_category_page_title( $title ) {
        $title_arr = explode(':', $title);
        if ( count($title_arr) > 0 ){
            if(array_key_exists(1, $title_arr)) {
                return $title_arr[1];
            }
        }
        return $title;
    }
    add_filter( 'pre_get_document_title', 'change_category_page_title', 9999 );
    
    Login or Signup to reply.
  2. You can use the filter get_the_archive_title for that:

    function set_archive_title( $title ) {
        if ( is_category() ) {
            $parts = explode( ':', $title );
            
            unset( $parts[0] );
            
            $title = trim( implode( ' ', $title ) );
        }
        
        return $title;
    }
    
    add_filter( 'get_the_archive_title', 'set_archive_title' );
    

    This splits the string in array parts for every occurring :. Then the first part of the array gets removed and then the remaining parts are changed back to a string.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search