[wp-hackers] Prepend blog name in comment feed's title

Peter Westwood peter.westwood at ftwr.co.uk
Sat Oct 10 07:59:27 UTC 2009


On 10 Oct 2009, at 01:17, Thomas Scholz wrote:

> Peter Westwood:
>
>> There is a filter on the "Comments on" bit.
>>
>> If you dig into the translation functions there are filters to let  
>> plugins modify the translated string which can be used to prepend  
>> something here.
>
> Thanks, that was it!
>
> Here's my code (replace 'Kommentare zu:' with 'Comments on:' in  
> english blogs):
>
> // functions.php
> add_filter('gettext', 'rss_title_prefix');
>
> function rss_title_prefix($str)
> {
> 	if ( is_feed() AND is_singular() )
> 	{
> 		return str_replace('Kommentare zu:', get_bloginfo('name') . ' -  
> Kommentare zu:', $str);
> 	}
> 	return $str;
> }
>
> I've updated my blog post at <http://toscho.de/2009/wordpress-kommentarfeed-blogname/ 
> >.

This is really good... but you can do even better.

The filter passes in a lot more useful info.

(follow code is untested even by a php interpreter)

add_filter('gettext', 'rss_title_prefix', 10, 3)

function rss_title_prefix($translation, $original, $domain) {
	if ( ( 'default' == $domain ) && ('Comments on: %s' == $original) {
		return get_bloginfo('name') . ' - ' . $translation;
	}
	return $translation;
}


This will ensure you match the exact string (and it works for any  
language.

Peter
-- 
Peter Westwood
http://blog.ftwr.co.uk | http://westi.wordpress.com
C53C F8FC 8796 8508 88D6 C950 54F4 5DCD A834 01C5



More information about the wp-hackers mailing list