0

I want to change the title of my archive page from "category" to "department" to get something like this: Department: Marketing. Where "department" is the archive page title and "Marketing" is the actual name. This is the code that I used:

add_filter( 'get_the_archive_title', function ( $title ) {

    if( is_category() ) {

        $title = 'department';

    }

    return $title;

});

But It hides the page name. When I use this code, I get only "Department" as a title and when I delete it, I get "category: department".

How to fix it?

1

You need to add the actual page title back in. Try this:

add_filter( 'get_the_archive_title', function ( $title ) {
    if( is_category() ) {
        $title = 'Department: '. single_cat_title( '', false );
    }
    return $title;
});
2
  • Yes, that worked perfectly! thanks a lot dear @rudtek – joseph Jan 12 at 3:03
  • Great news. Can you mark it as answered? (it's the checkmark on the left of the question) – rudtek Jan 12 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.