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.

Author: Greg Rickaby

Greg is Lead Front-End Developer at WebDevStudios and author of a children's book titled, Creating a Website: Design and Build Your First Site!.

Leave a Reply