Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress如何根据我的文章标题更改页面标题_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php Wordpress如何根据我的文章标题更改页面标题

Php Wordpress如何根据我的文章标题更改页面标题,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我想wordpress应该显示所选文章和所选页面的标题。我正在使用商业新闻主题。他们的任何设置是否可用,或者我需要更改代码我是wordpress的新手。我在header.php中找到了标题代码 <title><?php //Print the <title> tag based on what is being viewed. global $page, $paged; // Add the blog name. bloginf

我想wordpress应该显示所选文章和所选页面的标题。我正在使用商业新闻主题。他们的任何设置是否可用,或者我需要更改代码我是wordpress的新手。我在header.php中找到了标题代码

<title><?php
    //Print the <title> tag based on what is being viewed.
    global $page, $paged;   
    // Add the blog name.
    bloginfo( 'name' );
    // Add the blog description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ) echo " | $site_description";
    // Add a page number if necessary:
    if ( $paged >= 2 || $page >= 2 )
        echo ' | ' . sprintf( __( 'Page %s', 'business-news' ), max( $paged, $page ) );
?></title>

但当我选择“发布”时,标题中只显示站点名称。我在哪里失踪

试试这个:

<title>
    <?php single_post_title(); ?>
</title>

使用


您可以简单地使用:

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


有关更多帮助,请通过此方式转到“管理显示有效标题的每个位置”。比如.404和搜索页面。
 function theme_name_wp_title( $title, $sep ) {
    if ( is_feed() ) {
        return $title;
    }

    global $page, $paged;

    // Add the blog name
    $title .= get_bloginfo( 'name', 'display' );

    // Add the blog description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ) {
        $title .= " $sep $site_description";
    }

    // Add a page number if necessary:
    if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
        $title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
    }

    return $title;
}
add_filter( 'wp_title', 'theme_name_wp_title', 10, 2 );
 <title><?php wp_title(); ?></title>