1

I inherited a problem that no one in my office can figure out.

Our company website has page titles in the format of "Page Name Company Name - Company Name." The first instance of Company Name is a duplicate and needs to be deleted (it should be Page Name - Company Name), but I'm not sure how to proceed from looking at the code. This is a custom WP theme that is a child of the 2014 stock theme. Does anything in this title code snippet stand out?

<title>
       <?php
          if (function_exists('is_tag') && is_tag()) {
             single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; }
          elseif (is_archive()) {
             wp_title(''); echo ' Archive - '; }
          elseif (is_search()) {
             echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; }
          elseif (!(is_404()) && (is_single()) || (is_page())) {
             wp_title(''); echo ' - '; }
          elseif (is_404()) {
             echo 'Not Found - '; }

          if (is_home()) {
             bloginfo('name'); echo ' - '; bloginfo('description'); }
          else {
              bloginfo('name'); }
          if ($paged>1) {
             echo ' - page '. $paged; }
       ?>
</title>
  • If you go to Settings -> General do you have Company Name in both the Site Title and Tagline field? – Howdy_McGee May 17 '16 at 19:40
  • Nope, it's just in the site title field. – hjarta May 17 '16 at 19:42
  • Do you have any SEO plugins installed such as Yoast that you could disable? – Howdy_McGee May 17 '16 at 19:44
  • Nope! :) No SEO plugins on this site. – hjarta May 17 '16 at 19:45
  • Do you have a fragment like this add_theme_support( 'title-tag' ); – prosti May 17 '16 at 20:51
1

You're on a page and if we read through the list of conditionals it should hit this one specifically:

elseif( ! ( is_404() ) && ( is_single() ) || ( is_page() ) ) {
    wp_title( '' );
    echo ' - ';
}

It will also hit the below conditional in the next set:

else {
    bloginfo( 'name' );
}

Given page Test Page we should see Page Name - Company Name but the parent Twenty Fourteen theme has this filter on wp_title():

function twentyfourteen_wp_title( $title, $sep ) {
    global $paged, $page;

    if ( is_feed() ) {
        return $title;
    }

    // Add the site name.
    $title .= get_bloginfo( 'name', 'display' );

    // Add the site description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ) {
        $title = "$title $sep $site_description";
    }

    // Add a page number if necessary.
    if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
        $title = "$title $sep " . sprintf( __( 'Page %s', 'twentyfourteen' ), max( $paged, $page ) );
    }

    return $title;
}
add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 );

Notice that it is also appending the Website Name to the title ( directly after the feed conditional ) which is why we end up seeing the company name twice. You can comment out the above line to remove the duplication.

function twentyfourteen_wp_title( $title, $sep ) {
    global $paged, $page;

    if ( is_feed() ) {
        return $title;
    }

    // DONT Add the site name.
    // $title .= get_bloginfo( 'name', 'display' );

    // Add the site description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ) {
        $title = "$title $sep $site_description";
    }

    // Add a page number if necessary.
    if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
        $title = "$title $sep " . sprintf( __( 'Page %s', 'twentyfourteen' ), max( $paged, $page ) );
    }

    return $title;
}
add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 );
0

Check the add_theme_support( 'title-tag' );

https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/

function theme_slug_setup() {
   add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'theme_slug_setup' );

By declaring support like this, themes acknowledge that they are not defining titles on their own and WordPress can add it safely without duplication.

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.