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

Andy Staines andy at yellowswordfish.com
Wed Jan 9 01:21:08 GMT 2008


Sorry yes - I got side-tracked!
Again - similar solution to the one Rob suggested (although I didn't  
know you could use is_page() like that) with the same caveat - I have  
to run a query to get the page title. But thanks for the response. All  
suggestions welcome!
andy

On 9 Jan 2008, at 01:07AM, Williams Phillip wrote:

> Sorry if you already got this but I am not sure that the first one  
> made it through.
>
> How about something like:
>
> function filter_current_page_title( $title) {
> 	if (is_page( $title) ) {
> 		return "new title";
> 	}
> }
> add_filter('the_title', 'filter_current_page_title');
>
> I am still pretty new to WP, so take it with a grain of salt...
>
> Phil
> phil.m.williams at gmail.com
>
>
>
> On Jan 8, 2008, at 5:12 PM, Andy Staines wrote:
>
>> 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
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> 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