[theme-reviewers] Usage of wp_title filter.

WPForever Team hi at wpforever.com
Wed Oct 17 14:29:45 UTC 2012


Yes, Philip is correct.

This is how TwentyTwelve does it - 
http://core.trac.wordpress.org/browser/trunk/wp-content/themes/twentytwelve/functions.php#L168

Philip M. Hofer (Frumph) wrote:
>
> That is precisely how to do it. But you should also return the
> original $title being passed through the filter
>
> This is how I do it (not totally pretty), notice the check for the
> feed if it is the feed it returns the original $title .. I probably
> could have gotten away with just doing = .= with $title in the
> !is_feed() section ;/
>
> function easel_filter_wp_title( $title ) {
> global $wp_query, $s, $paged, $page;
> if (!is_feed()) {
> $sep = __('»','easel');
> $new_title = get_bloginfo('name').' ';
> $bloginfo_description = get_bloginfo('description');
> if ((is_home () || is_front_page()) && !empty($bloginfo_description)
> && !$paged && !$page) {
> $new_title .= $sep.' '.$bloginfo_description;
> } elseif (is_single() || is_page()) {
> $new_title .= $sep.' '.single_post_title('', false);
> } elseif (is_search() ) {
> $new_title .= $sep.' '.sprintf(__('Search Results: %s','easel'),
> esc_html($s));
> } else
> $new_title .= $title;
> if ( $paged || $page ) {
> $new_title .= ' '.$sep.' '.sprintf(__('Page: %s','easel'),max( $paged,
> $page ));
> }
> $title = $new_title;
> }
> return $title;
> }
>
> add_filter( 'wp_title', 'easel_filter_wp_title' );
>
> -----Original Message----- From: esmi at quirm dot net
> Sent: Wednesday, October 17, 2012 7:16 AM
> To: theme-reviewers at lists.wordpress.org
> Subject: [theme-reviewers] Usage of wp_title filter.
>
> I've just been reviewing the Codex page on the wp_title() filter:
>
> <http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title>
>
> Specifically the example quoted as best practice. When I've tried to
> implement that function, it generates a duplicated title in the RSS
> feed. This can be circumvented by changing:
>
> return get_bloginfo( 'name' ) . $page_type . $title . $page_num;
>
> to:
>
> if( !is_feed() ) return get_bloginfo( 'name' ) . $page_type . $title .
> $page_num;
>
> but I'm not 100% convinced that this is the proper usage of is_feed().
>
> Anyone care to comment before I amend the Codex page?
>
> Mel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20121017/3d396754/attachment-0001.htm>


More information about the theme-reviewers mailing list