Filter and clean the Archive Title

This client wanted to feature their archive titles in a large hero area. The PSD excluded the prefixes like, “Category:”, “Tag:”, “Author:”, etc…

The snippet below allows you to strip out the prefixes used in the get_the_archive_title(); function, as well as any HTML tags.

Screenshot of the clean archive title

Screenshot of the “clean” archive title.

Jeremy Pry helped me solve this by inserting this regular expression into PHP’s preg_replace();  function. It executes a find and replace on the $title variable.

https://gist.github.com/gregrickaby/a15422be00e46e3ec5532f9bdd9ed484

About Greg Rickaby

Director of Engineering @WebDevStudios / Author & Tech Editor @ForDummies / @WordPress Contributor / @gatsbyjs Maintainer

1 Comment

  1. MaquiJacob on October 16, 2017 at 8:07 pm

    Thank you! Very helpful!

Leave a Comment