3

My current <title> tags are like this:

Blog post title | Site name

How do I remove "Site name" so that the <title> tags will be like this:

Blog post title

Except, of course, on the front page, where the <title> tag should be:

Site name

Please take into account that I'm a complete Wordpress newbie.


Edit: Here's my current <title> tag from header.php:

<title>
<?php
if ( defined( 'WPSEO_VERSION' ) ) {
    // WordPress SEO is activated
        wp_title();

} else {

    // WordPress SEO is not activated
    wp_title( '&#124;', true, 'right' );
}
?>
</title>
  • If you have any SEO plugin active, try to find its title settings. If not, tell us. :) – fuxia Apr 9 '13 at 12:36
  • I don't have any SEO plugins active. – Miscreant Apr 9 '13 at 12:39
  • 2
    Then why do you have the if ( defined( 'WPSEO_VERSION' ) ) {} conditional? – Chip Bennett Apr 9 '13 at 12:47
6

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( '&#124;', 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' );
  • My parent theme was adding the blog name to the title. I was able to use this solution to still fix it by simply increasing the priority parameter to the add_filter call. This ensure that our new filter executes after the parent-theme's filter. I set the priority to 100: add_filter('wp_title', 'wpse95147_filter_wp_title', 100); – Kyle Sep 5 '14 at 17:04
  • +1 for "something is adding it (perhaps your Theme?)." – Joshua Goossen May 4 '15 at 20:44
1

Add this line in your header.php file

<title><?php wp_title();?></title>

Add Below code in theme's functions.php file

function your_wp_title( $title, $sep ) {
    global $paged, $page;
    if(is_front_page()){        
        $title = get_bloginfo( 'name' );   
        return $title;
    } else {
        if ( is_feed() )            
        // Add the site name.
        return $title;
    }
}
add_filter( 'wp_title', 'your_wp_title', 10, 2 );

Reference:http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title

0

On my template file header.php I replaced the title line by this

<title><?php is_front_page() ? woo_title() : wp_title( '' ); ?></title>

In my case I am using a woothemes template, that's why that woo_title() output.

Here, you can check in a single line if you are on home page, if true, you can allow to display the blog/site title, if false output the title without the site name, just will display your post or page title.

0

i was haveing this issue with posts so i searched the interet and i made a little plugin that remove the blog name from the posts

########### start remove blog title from posts #######
 function wp_abdul0201_wp_title( $title ) {
    if ( is_single() ) {
        $title = single_post_title( '', false );
    }
    return $title;
}
add_filter( 'pre_get_document_title', 'wp_abdul0201_wp_title' );
########### end remove blog title from posts #######

please notince this code

if ( is_single() )

it only applies to posts title you can add more codition like

if ( is_single() || is_archive ) 

here i added archive pages too i hope you got a general idea of how it works

-1
<?php wp_title(false); ?>

Try this and also read more here

&#124;indicates vertical bar as separator. true argument stands for $display, whether to display the title or no. Third arugment is position where to put separator.

  • Please add an explanation to your answer: why could that solve the problem? Where is the site name in your answer? – fuxia Apr 9 '13 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.