The best (and easiest) thing to do is to use the wp_title
filter.
First, clean up your call to <?php wp_title(); ?>
in your template. Replace what you have with this:
wp_title( '|', true, 'right' );
Then, in functions.php
(or in a child Theme functions.php
; normal caveats apply), add the following:
function wpse95147_filter_wp_title( $title ) {
if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
$title = single_post_title( '', false );
}
return $title;
}
add_filter( 'wp_title', 'wpse95147_filter_wp_title' );
This filter will completely overwrite the $title
output in single-page contexts. (The actual conditional is taken directly from core, from the wp_title()
function definition itself.)
Last I checked, WordPress doesn't actually output the site title anywhere in wp_title()
; so if you're seeing that, something is adding it (perhaps your Theme?). Nevertheless, if you want to output it, just write a complimentary conditional in the above filter; e.g.:
function wpse95147_filter_wp_title( $title ) {
if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
$title = single_post_title( '', false );
}
if ( is_front_page() && ! is_page() ) {
$title = esc_attr( get_bloginfo( 'name' ) );
}
return $title;
}
add_filter( 'wp_title', 'wpse95147_filter_wp_title' );
if ( defined( 'WPSEO_VERSION' ) ) {}
conditional?