I'm focusing on a wordpress wordpress plugin that modifies the title of the publish. I only do after i am viewing just one publish. To be precise, I wish to give a link near the title, however for reasons from the question, I'll be adding some arbitary text.

I began out using the 'the_title' filter hook, and calling this function.

function add_button_to_title($title)
{
  global $post;
  if(is_single())
  {
    return $title.'googly googly';
  }
  return $title;
}

The issue is, the hyperlinks quietly bar apparently also employ 'the_title', when i saw my text turning up within the side bars too, which brought me to:

if(is_single() && in_the_loop())

However, during my theme(and that i suppose styles generally) there's a hyperlink towards the previous publish and then publish, that also uses 'the title' filter. So finally I've:

if(is_single() && in_the_loop() && ($post->post_title == $title))

The final conditional essentially ensures that it's the title from the publish that's being printed, not the title from the next or previous publish. This works but I don't know how good it'll work given different styles...It appears like terribly compromised together. Any advice from wordpress gurus available? I'm worried the title could be modified for some other reasons and also the conditional will fail.

Any assistance is appreciated!

Ying,

There is not really a great choice except, as ShaderOp stated, needing theme modification. Your solution works typically. The only real exception is that if the theme developer has transformed the query inside a page. I'd say this really is most likely a reasonable solution that it's going to cover a lot more than 95% from the cases you'd encounter.

Would not it be simpler to help keep the initial version of the add_button_to_title function, but rather than connecting it to some filter, refer to it as from your single.php page within the appropriate place?

For instance, somewhere inside your theme's single.php, rather than this:

<h3 class="storytitle">
    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</h3>

Make use of this:

<h3 class="storytitle">
    <a href="<?php the_permalink() ?>" rel="bookmark">
        <?php echo add_button_to_title(the_title('', '', false); ?>
    </a>
</h3>

I solved an identical problem with the addition of a determine when the title being strained matches the title from the publish. This eliminates the problem along with other publish game titles around the page (in sidebar, menu) also getting strained.

function add_button_to_title( $title ) {
  global $post;
  if( is_single() && $title == $post->post_title ) {
    return $title . 'googly googly';
  } else {
    return $title;
  }
}