How to Hide the Archive Title Prefix in WordPress

I don’t remember exactly when it happened but about a year ago WordPress introduced a prefix at the front of WordPress archive titles. This prefix is designed to give context to archives. For example it helps to distinguish between tag and category archives. Or more importantly between category and custom post type archives (such as a portfolio).

The problem is – a lot of website users don’t like this. It’s not very attractive, and makes the title a lot larger. One solution is to edit your theme code and display something else, but that’s not ideal since it will break when themes are updated.

With my own (recent) themes I have used a filter to wrap the prefix and apply some styles to it so that it integrates better with the rest of the layout.

An example of the archive title prefix being wrapped in my theme Carmack

An example of the archive title prefix being wrapped in my theme Carmack

Since I was asked about it again today I thought I would modify the code slightly and publish some simple code that can be used as a plugin to do the same thing.

What the code does is split the archive title by a :, the character used to separate prefix from the actual title, wrap the first part of the title, and then glue them back together. In this plugin I am using the ‘screen-reader-text’ class to hide the text. This is a class that’s marked as ‘required’ by WordPress and is used to hide text that should still be readable by screen-readers.

How to use this

To make use of the plugin save the raw php and upload it to your site. Once activated it ‘should’ just work. No options needed.

Stick it on the plugin repository already

The reason I haven’t made this an official plugin is that I know that WordPress will be wrapping the prefix in a span in a future update (you can see the trac ticket here). However because the WordPress release schedule has changed this year – I don’t know when the merge will happen.

Gotchas

One caveat with this is that it only works for left to right languages. It can be modified relatively easily to work with right to left languages, but I couldn’t work out an elegant way to make the code work nicely for both. I’d be happy to take suggestions for improvements if anyone can help improve this.

Something else to keep in mind is that this will only work when using 'the_archive_title' function. If your theme is older and uses some other method for outputting the archive title then it won’t work.

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

WordPress News

The latest WordPress updates from the WPBriefs Podcast.

Related Posts

01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...
08 Aug 2013

The Death of WordPress Theme Frameworks

WordPress theme frameworks are on their way out. They’re dying a slow death. At least that’s what I think.Nathan Rice recently wrote an article with his thoughts about theme frameworks – in defense of them – however he clearly has...
04 Nov 2016

Automating WordPress Development with Gulp, Bash, and PHP

When I wrote about the things I had learned from releasing 20 WordPress themes, I mentioned that I had automated as much as I could. One of the things I automated was the build and deployment process for my themes...
22 Nov 2014

WordPress 4.1 Improvements for Theme Developers

WordPress 4.1 is bringing with it a couple of cool new additions for theme developers. They’re things that are currently a bit messy to implement in themes. For me they are things that I do the same way in all...
04 Jan 2017

2016 – a Year Reviewed

What a year – when 2016 started I didn’t expect it to play out as it did. It was an eventful year in more ways than one.Personally the biggest change was becoming a father. My son, Sebastian, was born on...
13 Oct 2016

Lessons Learned from 20 Theme Releases on WordPress.com

In 2007 I partnered with Darren Hoyt to release Mimbo Pro, one of the earliest premium WordPress themes. In 2012 Mimbo Pro was published on wordpress.com. Last week – on October 5th 2016 to be precise – my 20th theme...