Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Novalyyn on "Filter to post title only"

$
0
0

In the plugin I'm working I'm trying to filter a little piece into the titles of posts, but only when that post is being shown. I have a quick is_single() check to prevent it from showing up on other pages.

However, it's being added to all titles on the single post page, including titles in navigation and links to other posts. I was thinking that I might be able to make it show only for the post by telling it to work only while dealing with things in the loop, but I'm not sure how to go about doing that.

What I have presently is basically:

function display_string( $title ) {
  if ( ! is_single() ) {
    return $title;
  }

  $my_string = 'test value';
  return $my_string . $title;
}

add_filter( 'the_title', 'display_string' );

Viewing all articles
Browse latest Browse all 8245

Trending Articles