Most everyone has their own way of writing this function, but this is what I use (or a slight variation) in all of my themes:<br><br><div style="margin-left:40px"> /**<br> * Use as filter input<br> *<br>
* @param string $old_title - default title text<br> * @param string $sep - separator character<br> * @param string $sep_location - left|right - separator placement in relationship to title<br>
*<br> * @return string - new title text<br> */<br> function dmm_wp_title( $old_title, $sep, $sep_location ) {<br> global $page, $paged;<br> /** Set initial title text */<br>
$dmm_title_text = $old_title . get_bloginfo( 'name' );<br> /** Add wrapping spaces to separator character */<br> $sep = ' ' . $sep . ' ';<br><br> /** Add the blog description (tagline) for the home/front page */<br>
$site_tagline = get_bloginfo( 'description', 'display' );<br> if ( $site_tagline && ( is_home() || is_front_page() ) )<br> $dmm_title_text .= "$sep$site_tagline";<br>
<br> /** Add a page number if necessary */<br> if ( $paged >= 2 || $page >= 2 )<br> $dmm_title_text .= $sep . sprintf( __( 'Page %s', 'desk-mess-mirrored' ), max( $paged, $page ) );<br>
<br> return $dmm_title_text;<br> }<br> add_filter( 'wp_title', 'dmm_wp_title', 10, 3 );<br></div><br>The point being not so much the code in this case but the fact I am not seeing duplicate titles *and* I am not testing for `is_feed` either.<br>
<br><br clear="all">Cais.<br>
<br><br><div class="gmail_quote">On Wed, Oct 17, 2012 at 10:29 AM, WPForever Team <span dir="ltr"><<a href="mailto:hi@wpforever.com" target="_blank">hi@wpforever.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Yes, Philip is correct.<br>
<br>
This is how TwentyTwelve does it - <a href="http://core.trac.wordpress.org/browser/trunk/wp-content/themes/twentytwelve/functions.php#L168" target="_blank">http://core.trac.wordpress.org/browser/trunk/wp-content/themes/twentytwelve/functions.php#L168</a><div>
<div class="h5"><br>
<br>
Philip M. Hofer (Frumph) wrote:<br>
<blockquote type="cite"><br>
That is precisely how to do it. But you should also return the <br>
original $title being passed through the filter<br>
<br>
This is how I do it (not totally pretty), notice the check for the <br>
feed if it is the feed it returns the original $title .. I probably <br>
could have gotten away with just doing = .= with $title in the <br>
!is_feed() section ;/<br>
<br>
function easel_filter_wp_title( $title ) {<br>
global $wp_query, $s, $paged, $page;<br>
if (!is_feed()) {<br>
$sep = __('&raquo;','easel');<br>
$new_title = get_bloginfo('name').' ';<br>
$bloginfo_description = get_bloginfo('description');<br>
if ((is_home () || is_front_page()) && !empty($bloginfo_description) <br>
&& !$paged && !$page) {<br>
$new_title .= $sep.' '.$bloginfo_description;<br>
} elseif (is_single() || is_page()) {<br>
$new_title .= $sep.' '.single_post_title('', false);<br>
} elseif (is_search() ) {<br>
$new_title .= $sep.' '.sprintf(__('Search Results: %s','easel'), <br>
esc_html($s));<br>
} else<br>
$new_title .= $title;<br>
if ( $paged || $page ) {<br>
$new_title .= ' '.$sep.' '.sprintf(__('Page: %s','easel'),max( $paged, <br>
$page ));<br>
}<br>
$title = $new_title;<br>
}<br>
return $title;<br>
}<br>
<br>
add_filter( 'wp_title', 'easel_filter_wp_title' );<br>
<br>
-----Original Message----- From: esmi at quirm dot net<br>
Sent: Wednesday, October 17, 2012 7:16 AM<br>
To: <a href="mailto:theme-reviewers@lists.wordpress.org" target="_blank">theme-reviewers@lists.wordpress.org</a><br>
Subject: [theme-reviewers] Usage of wp_title filter.<br>
<br>
I've just been reviewing the Codex page on the wp_title() filter:<br>
<br>
<<a href="http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title" target="_blank">http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title</a>><br>
<br>
Specifically the example quoted as best practice. When I've tried to<br>
implement that function, it generates a duplicated title in the RSS<br>
feed. This can be circumvented by changing:<br>
<br>
return get_bloginfo( 'name' ) . $page_type . $title . $page_num;<br>
<br>
to:<br>
<br>
if( !is_feed() ) return get_bloginfo( 'name' ) . $page_type . $title .<br>
$page_num;<br>
<br>
but I'm not 100% convinced that this is the proper usage of is_feed().<br>
<br>
Anyone care to comment before I amend the Codex page?<br>
<br>
Mel</blockquote></div></div></div>
<br>_______________________________________________<br>
theme-reviewers mailing list<br>
<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
<a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
<br></blockquote></div><br>