Frage

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?

War es hilfreich?

Lösung

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;
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top