Remove "Category:" in title for category pages

How do I change/remove the “Category:” prefix on category pages? I have had no luck with finding how to change that.

Sage uses the default WP function get_the_archive_title() in lib/titles.php.


1 Like

Where should the get_the_archive_title function be added if you are editing it? I can’t work out if it should be extras or setup?

Look at the end of the get_archive_title function, there is a filter you can hook into.

Since this is a WP function, you would not edit it. That’s what hooks and filters are for. If you wanted to, you could also create your own function with it’s own logic for outputting archive titles. Your call.

Yes, I get that but I’ve tried to hook it in setup and in extras. Neither work. The usual wordpress way is to use functions.php, which is frowned upon in Sage.

For reference, it’s helpful to have more information than “it doesn’t work”. Are there any errors or warnings being displayed? Logs say anything? What else have you tried?

However, since you said it doesn’t work in two separate files, you probably are not passing the namespace:

Also, feel free to put functions wherever makes sense to you. In Sage, functions and classes are separated into files for organization. They are still all loaded from functions.php

Fair point, but my question was simply about organisation in the ‘Sage way’. Is this an extra, or is it a setup? The Sage documentation prefers this NOT to be in functions.php.

If the point is subjective, then it seems to make more sense to me as a setup.

@apa1exakis, it would be something along the lines of (as per described in the WP Codex link @chriscarr’s first reply) :

    function get_the_archive_title() {

    if ( is_category() ) {
$title = sprintf( __( 'Don't say category here: %s' ), single_cat_title( '', false ) );
    return apply_filters( 'get_the_archive_title', $title );

This topic was automatically closed after 4 hours. New replies are no longer allowed.

There was some confusion on this subject, exactly how to go about this using the Sage theme. Although this has been covered multiple times on the forum and in WP in general, I’m going to explain how you would accomplish this.

First of all, as @chris mentioned, get_the_archive_title is used. That WP function contains a filter:

return apply_filters( 'get_the_archive_title', $title );

In order to remove the Category: part from the title, a simple str_replace() call would probably be easiest. So your function might look like this:

function filter_category_title($title) {
  return str_replace('Category: ', '', $title);

When adding hooks or filters in your Sage theme, the only difference is you should add the namespace. There are already a few examples in the stock Sage code:

So putting it all together, you would add this to a file in your lib folder:

function filter_category_title($title) {
  return str_replace('Category: ', '', $title);
add_filter('get_the_archive_title', __NAMESPACE__ . '\\filter_category_title');

You could also run a check if it’s on the Category page, but if it’s not then nothing will be replaced anyways.