How to change the WordPress Category title and remove “Category:”

📂 Category: PHP

🖺 Last modified: 2nd Jan 2020

💻 Experience: Intermediate

🕑 Read Time: 4 min

Tired of the default title format on WordPress Category pages and Archives? In this tutorial we’ll show you how to change the boring Category: Category name format to any custom title you want. You’ll learn how to remove “Category:” prefix, and display a different WordPress Category title for each post category.

Introduction: Understanding the WordPress Category hierarchy

To begin the process of changing the WordPress Category title, firstly we have to locate the Category page template. In most themes the category template file is located in the theme’s root folder. You should see it in the files list on the right side of your Theme editor. Depending on the theme, you should look for the archive.php or category.php file. In some cases you’ll find both files in the list.

According to the WordPress Category hierarchy, if the category.php file exists, it will be used to generate the category page. If category.php doesn’t exist, the WordPress category page will be generated from the archive.php file.

Respecting the Category hierarchy, to change the WordPress Category title and remove “Category:” prefix, we’ll edit the category.php file. In case category.php is not present, we’ll edit the archive.php file.

PRO TIP: For easier editing of PHP files we suggest using a Syntax Highlighter plugin, if your theme editor doesn’t higlight code by default. To find out more check our article on Syntax highlighting in WordPress. When editing WordPress template files, make sure you created a Child theme and copied the files you’re going to edit. That way the modifications won’t get lost once you update the theme.

Example of how to change WordPress Category title

Example of a custom WordPress Category title on our web site.

 

How to remove “Category:” and change the Category page title

In this simple example we’ll show you how to remove “Category:” and change the Category page title on a single category blog. That’s a blog that uses only one category for all it’s posts. Inside the category.php or archive.php file we need to locate the function the_archive_title() that prints out the category title. In some cases we might be looking for the single_cat_title() function. The function is usually inside the <header> section on the begining of the template file. The format of the category title function might be slightly different from theme to theme.

Examples of how the code that generates the WordPress Category Title might look like:

/* Twenty Nineteen Theme */
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
?>
</header><!-- .page-header -->

/* Twenty Seventeen Theme */

<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->

/* Another variation */

<header class="page-header">
<h1 class="page-title">
<?php the_archive_title(); ?>
</h1>
</header>

NOTE: the examples above show the code in the archive.php file. When editing the category.php file, the function single_cat_title() might be found instead of the_archive_title().

Now that we located the code that generates the Category page title, we simply need to delete it and replace with our custom title. It’s important to remove the whole function together with the opening and closing PHP tags <?php … ?>.

After, you’re done, the WordPress Category Title code should look something like this:

<header class="page-header">
<h1 class="page-title">My Custom Category Title</h1>
</header><!-- .page-header -->

Custom Category page title for multiple categories

The example above was an easy tweak for simple one category blogs. If your blog or web site has multiple categories, you need to display a different custom title for each category. In this case we’ll expand our final code snippet above with an if statement that checks the active category and displays it’s own custom category title.

Firstly you have to locate and remove the original code that generates the Category page title, as described in the previous example. Secondly, you have to add the code snippet bellow and customize it according to your needs. Replace the category slugs with your own and add as many if statements as needed.

<?php 
if (is_category('html-tutorials')) {
echo '<h1>Check out our awesome HTML Tutorials</h1>' ; } ;
			
if (is_category('learn-css')) {
echo '<h1>Learn how to beautifully style pages with CSS</h1>'; } 

if (is_category('php')) {
echo '<h1>Our advanced PHP programming tutorials</h1>'; } 
		
/* Repeat if statements as much as needed  */	
?>

Instead of using category slugs as is_category() function arguments, you can also use category id numbers, or even category names you defined when setting up categories. We prefer to use category slugs.

 

Learn more about WordPress Categories

To learn more on how to change the WordPress Category title and the is_category() function check the WordPress Developers Refference.