WordPress.org

Ready to get started?Download WordPress

Forums

Add prefix to post tiles in a certain category (5 posts)

  1. Mark
    Member
    Posted 2 years ago #

    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 :)

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Try something like:

    function add_podcast($title) {
    	$title = 'Podcast' . $title;
    	return $title;
    }
    add_filter('the_title', 'add_podcast');
  3. Mark
    Member
    Posted 2 years ago #

    Thanks esmi :)

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

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  5. Mark
    Member
    Posted 2 years ago #

    Sweet :)

    Thanks very much.

Topic Closed

This topic has been closed to new replies.

About this Topic