While configuring this blog, I thought about having a category segmentation, allowing me to have menus with each of them so that each user could pick the topics that interested them.
I created the posts, added the categories, and created menus that pointed to each of them. When the user wants to know more about “Opinion,” for example, I can show all the posts related to that. The template that I’m using even allows for neat navigation like “Home > Opinion.”
Awesome!
The issue is that in all pages I get the ugly title “Category: Opinion” like bellow:
I want to remove it, but I couldn’t find an option to do so. Some themes do support hiding this so, before going further, please check in the Theme specific settings if you can hide it.
After much digging, I found a few solutions that can help you.
Remove the “Category:” but keep the title
There’s an excellent explanation here in how to do this, but the gist of it is to add the following piece of code in your filefunctions.php
. To do so just:
- Log in with an account that has Administrator privileges
- Go to Appearance > Theme Editor
- Select Theme Functions
- Add the following code to the end of the function
function prefix_category_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
- Click Update File
You’ll get something like this:
Remove the “Category: ” and the title
Just follow the same steps as before but add the following code instead:
function prefix_category_title( $title ) {
if ( is_category() ) {
$title = '';
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
And it will disappear completely.
CSS Solution
Both previous solutions work fine until the template needs to be updated. The update process replaces all your files, so any change that you do is lost. You need to do this again and again for each update, and this is not very convenient. The solution is to add a custom CSS to the Theme that you’re using:
- Log in with an account that has Administrator privileges
- Go to Appearance > Customize
- Select Additional CSS
- Add the following code:
.category .page-header { display: none; }
- Click Publish.
That’s it. Quick and simple.
Bonus tip
You can apply this strategy to the “Author,” “Tags,” and “Archives.” Just follow the same steps and add the following code for each:
Author
.author .page-header { display: none; }
Tags
.tag .page-header { display: none; }
Archives
.archive .page-header { display: none; }
Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out other tutorial-related articles here.
Photo by Michael Dziedzic on Unsplash
Thanks, the CSS approach worked just fine for me
Thanks a lot, finally I found something that works.
Worked for me… Thanks!
Dont work to me 🙁
What to do when the category name is shown under the blog bost title???
Brilliant! Thank you for sharing!