How to remove the “Category:” prefix from the category title in the archive pages of a WordPress theme

To remove the “Category:” prefix from the category title in the archive pages of your WordPress theme, you can use the get_the_archive_title filter. Add the following code snippet to your theme’s functions.php file:

  1. In your WordPress admin dashboard, go to “Appearance” > “Theme Editor.”
  2. In the right sidebar, locate and click on the “functions.php” file.
  3. Add the following code snippet at the end of the file:
function my_theme_remove_category_prefix($title) {
    if (is_category()) {
        $title = single_cat_title('', false);
    }
    return $title;
}
add_filter('get_the_archive_title', 'my_theme_remove_category_prefix');

This code snippet creates a function called my_theme_remove_category_prefix() that checks if the current page is a category archive. If it is, the function replaces the full title with the category title without the “Category:” prefix using the single_cat_title() function.

  1. Click “Update File” to save the changes.

Now, the “Category:” prefix should be removed from the category titles on your category archive pages.

Remember to always backup your files before making any changes, and test your changes on a staging site or local development environment before applying them to your live site.

Leave a Reply

Your email address will not be published. Required fields are marked *