Why doesn’t my simple the_title filter get applied?

I have added the code below to an active plugin, but it’s having no effect on my posts.

add_filter( ‘the_title’, ‘myfunction’);

function myfunction($title) {
 return "Why won't this work?" . $title;
}

What am I missing here?

Read More

The post templates are definitely using the_title(), and the theme is normal (wp_head(), etc), and there are no conditionals surrounding the function in the plugin that would make it not run. I have also tried adding different priority in the add_filter function, from -9999 to 9999, to no effect.

Related posts

Leave a Reply

1 comment

  1. Try changing this:

    add_filter( ‘the_title’, ‘myfunction’);
    

    to this:

    add_filter( 'the_title', 'myfunction' );
    

    (If this is indeed your problem it is likely an issue of copy/pasting code from a tutorial with curly quotes in place of standard single-quote marks.)

    p.s. prefix your function name with your Plugin slug. “myfunction” is far too generic.