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

Andy Staines andy at yellowswordfish.com
Tue Jan 8 22:12:32 GMT 2008


Hi Rob
Oh yes - that works OK and is my fallback. In this instance I do not  
know the title - but I do know the page ID so I can run a query to  
retrieve the title. It works but it's a bit of a hammer to crack the  
proverbial nut. I can at least run the query just once so that it  
doesn't get called for each page when wp_list_pages() executes but  
it's not ideal. I still can't fathom the rationale behind calling the  
filter in the template tag in the first place.
So yes - as I say, it's my fallback - I was just hoping there may be a  
quicker method.
Thanks for the response.
Andy

On 8 Jan 2008, at 21:56PM, Rob wrote:

> 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/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list