简体   繁体   English

WordPress不显示| 在里面 <title> index.php上的属性

[英]Wordpress don't show | in the <title> attribute on the index.php

I am currently using this code to display the name of the post/page and of the blog in my wordpress theme: 我目前正在使用此代码在我的wordpress主题中显示帖子/页面的名称和博客的名称:

<title><?php wp_title(''); ?> | <?php bloginfo('name'); ?></title>

The problem is that the of the index.php looks like this: | 问题是index.php的看起来像这样: name of the blog 博客名称

How can I fix this? 我怎样才能解决这个问题?

Thanks in advance! 提前致谢!

In your functions.php add 在您的functions.php添加

add_theme_support( 'title-tag' );

And in your header under your Content-Type meta add, like this: 并在Content-Type元添加下的标头中,如下所示:

<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
<?php
    if ( ! function_exists( '_wp_render_title_tag' ) ) :
        function yourtheme_render_title() {
            ?>
            <title><?php wp_title( ' ', true, 'right' ); ?></title>
            <?php
        }
        add_action( 'wp_head', 'yourtheme_render_title' );
    endif;
?>

Should be working once you set the title of your blog/web page on the Settings. 在“设置”上设置博客/网页的标题后,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM