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

Chris Jean gaarai at gaarai.com
Fri Oct 9 20:57:55 UTC 2009


This code works. It's nasty, but it works.

    add_action( 'rss2_comments_ns', 'change_comment_feed_title' );

    function change_comment_feed_title() {
        ob_start( 'modify_comment_feed_title' );
        add_filter( 'pre_option_home', 'clear_buffering' );
    }

    function modify_comment_feed_title( $content ) {
        return preg_replace( '|<title>.+?</title>|', '<title>' . get_bloginfo( 'name' ) . ' Comments</title>', $content );
    }

    function clear_buffering( $return_false ) {
        ob_end_flush();

        return false;
    }

I added this to the theme's functions.php file for quick testing, but it
can be put into a plugin, etc.

Of course, you'll need to modify the regular expression to do whatever
you need to do with the title.

Chris Jean
http://gaarai.com/
http://wp-roadmap.com/
http://dnsyogi.com/



Thomas Scholz wrote:
> Hi,
>
> I'm looking for a way to prepend my blog name to the title of comment
> feeds for single articles.
>
> The template in WordPress (/wp-includes/feed-rss2-comments.php):
>
> <title><?php
>     if ( is_singular() )
>         printf(ent2ncr(__('Comments on: %s')), get_the_title_rss());
>     elseif ( is_search() )
>         printf(ent2ncr(__('Comments for %s searching on %s')),
> get_bloginfo_rss( 'name' ), esc_attr($wp_query->query_vars['s']));
>     else
>     printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss( 'name' )
> . get_wp_title_rss());
> ?></title>
>
> As you can see, I'm able to add a filter to 'the_title_rss' and add
> the blog name as a suffix.
> <http://toscho.de/2009/wordpress-kommentarfeed-blogname/>
>
> But how do I set the blog name in the first place? Any ideas?
>
> Thomas
>


More information about the wp-hackers mailing list