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

admin2025-06-02  1

I am submitting my theme to WordPress. 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="">
    <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.

I am submitting my theme to WordPress. 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/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.

Share Improve this question edited May 23, 2017 at 12:40 CommunityBot 1 asked Sep 20, 2015 at 11:26 user2238user2238
Add a comment  | 

2 Answers 2

Reset to default 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.

I solved this way:

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

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748826080a314041.html

最新回复(0)