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:

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 "'); echo '" | ';
} elseif (is_archive()) {
    wp_title(''); echo ' Archive | ';
} elseif (is_search()) {
    echo 'Search for "'.esc_html($s).'" | ';
} 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>

Read more here: Problem dynamically generating an all purpose title tag


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: