Forums

Modifying custom post type's title (3 posts)

  1. munzirstudio
    Member
    Posted 8 months ago #

    Hi,

    I have a problem here, I'm creating a restaurant directory, instead of typing restaurant word in the end of the restaurant's name for e.g 'Spice and Hot Restaurant' in the title field, can we just put Spice and Hot and we coded the restaurant in a function that echoed whenever the title being requested (in header, in post) wherever possible.

    Anybody knew how to do it?

    tq

  2. TCBarrett
    Member
    Posted 8 months ago #

    add_filter( 'the_title', 'tcb_cpt_title_prefix', 10, 2);
    function tcb_cpt_title_prefix( $title, $post_id ){
      if( 'restaurant' == get_post_type($post_id) ) :
        return $title . ' Restaurant';
      endif;
      return $title;
    }
  3. munzirstudio
    Member
    Posted 8 months ago #

    thanks a lot TCBarrett, it works..

    but there's only one little problem left, how to print the function into the <title> tag, it doesn't appeared in it. maybe something to do with wp_title hook?

Reply

You must log in to post.

About this Topic