0
<title> 

    <?php if ( is_single() ) {
        single_post_title('', true); 
    } else {
        bloginfo('name'); echo " - "; bloginfo('description');
    }
    ?>


    </title>

This is my title tag code used for my wordpress blog. But Seo analyst shows No title tag found error

  • 1
    Where is this code? And this isn't going to be dynamic for category or date archives. Why not just use wp_title(), or better yet add_theme_support( 'title-tag' )? – Jacob Peattie Mar 2 '18 at 15:36
  • Can you pls explain me detaily – Ramesh KR Mar 3 '18 at 5:55
0

single_post_title only works on single posts, so you are okay using this. First thing you could try is changing "true" to "false" to make the title be returned in the title tag you've created. If that doesn't fix it then try adding an h1 as below (which i don't think you'll need).

SEO is also looking for an H1 (title) tag i believe as well. If you enclose your single_post_title in an h1 tag it will eliminate your seo problem together with changing return output to false:

<h1><title> 

<?php if ( is_single() ) {
    single_post_title('', false); 
} else {
    bloginfo('name'); echo " - "; bloginfo('description');
}
?>

</title></h1>

The other option is to just use this:

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

There's no need to be adding your own title tag in a WordPress theme in 2018 (or 2014). Instead, in your theme's functions file you should leave the <title> tag out of your header and register your theme's support for title tags so that WordPress can add it for you:

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

Now WordPress will add the tag to your head for you and it will be completely dynamic and support all the standard WordPress pages/archives/URLs.

If you want to customise it further, you can use the document_title_parts hook, or if you want to change the separator, you can use document_title_separator hook.

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.