how do I filter single_cat_title to remove all instances of a particlular word

I have certain names in my category title (that need to stay there for other reasons). I am displaying all category titles with the blog name prefixed, but on categories that already have this name I would like to automatically remove the blog name from the single_cat_title. i.e. “My Blog My Blog Category” is what is showing using but where single_cat_title allready has the blogname as part of the title, I would like to only show “My Blog Category”. Can one do this with single_cat_title as I have used it everywhere and manually replacing these would be problemattic?

Related posts

Leave a Reply

1 comment

  1. There is a filter with the same name (single_cat_title) you can make use of to replace a particular word all the time:

    add_filter('single_cat_title', function($title) {
            return str_replace('word to replace', '', $title);
        })
        ;
    

    This should basically do the job.