Support » Fixing WordPress » Add prefix to post tiles in a certain category

  • Hi guys

    Is it possible to add some code (possibly to my functions.php file) that will prefix all post titles in a certain category with the word ‘Podcast’?

    Thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    (@esmi)

    Forum Moderator

    Try something like:

    function add_podcast($title) {
    	$title = 'Podcast' . $title;
    	return $title;
    }
    add_filter('the_title', 'add_podcast');

    Thanks esmi 🙂

    Just looking at your code, how does that only specify posts only within the pocdcast category?

    esmi

    (@esmi)

    Forum Moderator

    Oops – missed that bit. Change it to:

    function add_podcast($title) {
    	if( in_category( 'foobar' ) ) $title = 'Podcast' . $title;
    	return $title;
    }
    add_filter('the_title', 'add_podcast');

    and replace foobar with the slug of your chosen category.

    Sweet 🙂

    Thanks very much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add prefix to post tiles in a certain category’ is closed to new replies.