Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Related on this is that you can use wp_list_categories and pass it the 'echo=0' parameter. This lets you export into a string. You can then use PHP's str_replace() function on that string to replace what you want before you echo it back. This isn't exactly what you're looking for in your case, but is similar and may help others. –  Volomike Sep 19 '12 at 16:35

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
and so simple! thanks –  Innate Jan 14 '11 at 10:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.