0

The code (below) works fine on all pages but front-page.php in WordPress.

Specifically, it adds an extra pipe symbol to the beginning of the title tag.

For example, if the following is the homepage of the site, the title looks like this:

<title>| Acme Widgets | Custom Widgets for all occasions</title>

Note the pipe at the beginning? All other pages work as expected.

fyi, my "Reading Settings" are set to a static page (with selections for home & posts pages).

Please advise.

in header.php

<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;'.esc_html($s).'&quot; | ';
} elseif (!(is_404()) && (is_single()) || (is_page()) ) {
    wp_title(''); echo ' | ';
} elseif (is_404()) {
    echo 'Not Found | ';
} 
if ( is_home() || is_front_page() ) {
    bloginfo('name'); echo ' | '; bloginfo('description');
} else {
    bloginfo('name');
}
if ($paged > 1) {
    echo ' | page '. $paged;
} ?>
</title>
1

I wound up fixing it like this. All pages now work. But it looks ...well ...ugly.

<?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;'.esc_html($s).'&quot; | ';
} elseif (!(is_404()) && is_single() ) {
    wp_title(''); echo ' | ';
} elseif (is_404()) {
    echo 'Not Found | ';
} 
if ( is_front_page() ) {
    bloginfo('name'); echo ' | '; bloginfo('description');
} elseif ( is_page() || is_home() ) {
wp_title(''); echo ' | '; bloginfo('name');
} else {
    bloginfo('name');
}
if ($paged > 1) {
    echo ' | page '. $paged;
} ?>
-2
elseif (!(is_404()) && (is_single()) || (is_page()) ) {

In your configuration with a static page as the home page is_page() is also evaluating to true and thus your extra pipe.

It appears that the code for your home page has everything you need to display the title how you want, so you might simply exclude the home page from the check above:

elseif ( !( is_404() || is_home() || is_front_page() ) && ( is_single() || is_page() ) {

Maybe not the cleanest but I think that would produce what you're looking for.

  • the question is what to do about it. – sleeper Jun 27 '14 at 10:40
  • Perhaps it is more helpful after the edit – Phil Lewis Jun 27 '14 at 20:23

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.