WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My theme has support for title-tag add_theme_support('title-tag'), but I can't remove the wordpress description bloginfo('description') from <title> on Home page.

I'm trying using this filter with no success:

add_filter( 'wp_title', function ( $title, $sep ) {
    global $paged, $page;

    $title .= get_bloginfo( 'name' );

    if ( is_home() || is_front_page() )
        $title = "$title";

    return $title;
}, 10, 2 );
share|improve this question

wp_get_document_title() has some interesting filters - pre_get_document_title and document_title_parts.

/**
 * Filter the parts of the document title.
 *
 * @since 4.4.0
 *
 * @param array $title {
 *     The document title parts.
 *
 *     @type string $title   Title of the viewed page.
 *     @type string $page    Optional. Page number if paginated.
 *     @type string $tagline Optional. Site description when on home page.
 *     @type string $site    Optional. Site title when not on home page.
 * }
 */
add_filter( 'document_title_parts', function ( $title ) {

    if ( is_home() || is_front_page() )
        unset($title['tagline']);

    return $title;

}, 10, 1 );
share|improve this answer

The problem is the line:

$title = "$title";

You actually just change the $title to itself. If you change it to

$title = get_bloginfo( 'name' );

the returned title on the front page is going to be the name of your blog. You can put any string there. Also, it is not necessary to call the globals here.

Here is some code that should work:

add_filter( 'wp_title', function ( $title, $sep ) {

    $title .= get_bloginfo( 'name' );

    if ( is_home() || is_front_page() )
        $title = "Any string you want to have";

    return $title;

}, 10, 2 );
share|improve this answer
    
I think I found a cleaner solution. Thanks. – marcelo2605 Feb 26 at 10:45

Found a solution:

add_filter( 'pre_get_document_title', function ( $title ) {
    if(is_front_page()){
        $title = get_bloginfo();
    }
    return $title;
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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