0

I am submitting my theme to WordPress.org. To make it compatible with WordPress 4.1 and greater, I replaced wptitle() tag with add_theme_support( 'title-tag' ) but now the error has changed to following:

REQUIRED: The <title> tags can only contain a call to wp_title(). Use the wp_title filter to modify the output

Here is a snippet from my header code:

<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width">
    <title><?php add_theme_support( 'title-tag' ); ?></title>
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
    <![endif]-->
    <?php wp_head(); ?>
</head>

I have read this Github discussion and this StackOverflow question to solve my problem.

2

add_theme_support( 'title-tag' ) doesn't belong in your header template. It belongs in your functions.php file. Usually, it's best to wrap it in it's own function and hook it to after_setup_theme in order to allow plugins and child themes to override it later if they need to. So...

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

Once you have declared title support, you can remove the <title> tag from header.php altogether and WP will handle putting it in.

| improve this answer | |
0

I solved this way:

<title><?php wp_title( '|', true, 'right' ); ?></title>

and write this into after_setup_theme function add_theme_support( 'title-tag' );

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy