Support » Plugins » Trouble with the_title in a plug-in

  • I’m trying to write a simple little plug-in to modify the title on the fly. My understanding is that I use the_title as the filter to apply, as in this example:

    function foo($text) {
    $text = str_replace('abc','def',$text);
    $text = "<div id='test'> . $text . "</div>";
    return $text;

    add_filter('the_title', 'foo');

    While this works, the problem is that $text holds two instances of title — the title itself, and the title as used in the permalink. When the line adding the <div> is executed, the permalink is also modified.

    Is there a relatively simple way to do what I want — that is, the objective is to identify a post (I have that bit working) and then based on that identification, modify the headline, date, and content using another style?

    I’m aware of Asides, but I don’t need these items to be in a linked list, and the solution seemed overly complex. Except for the issue with the_title being duplicated, I think I’m nearly there.

    Any help appreciated;


  • The topic ‘Trouble with the_title in a plug-in’ is closed to new replies.