[wp-hackers] Ticket #4267 - 'the_title' Filter

Rob r at robm.me.uk
Tue Jan 8 21:56:02 GMT 2008


On Jan 8, 2008 9:48 PM, Andy Staines <andy at yellowswordfish.com> wrote:
> I am hoping someone might be able to suggest a workaround for the
> above problem I raised a while  back. In short, sometime after 2.1.3,
> 'the_title' filter was added to wp_list_pages(). The result is that if
> you run a filter on 'the_title' to change the title of a specific page
> and wp_list_pages() is being used (on a navbar or sidebar) then ALL
> page titles get changed.
>
> Testing in the filter to confirm that the current page being displayed
> is the one you want to modify so that your code runs will, of course,
> test positive for every call to the filter - hence all page titles get
> corrupted.
>
> Can anyone think of a way that I can isolate the one page I need to
> change and make the change without effecting all other page listings?
> Sure be grateful for any suggestions...
>
> Thanks
> Andy

Apologies if I'm misunderstanding, but can you not filter based on the
existing title?

function foo_the_title( $title ) {
    if ( 'About' == $title ) {
        return 'New Title';
    }
    return $title;
}
add_filter('the_title', 'foo_the_title');


-- 
Rob Miller
http://robm.me.uk/


More information about the wp-hackers mailing list