WordPress.org

Forums

Modifying custom post type's title (3 posts)

  1. George Abbas
    Member
    Posted 2 years 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 2 years 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. George Abbas
    Member
    Posted 2 years 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?

Topic Closed

This topic has been closed to new replies.

About this Topic