问题是在我的一个寻呼机网站上没有填充标题标签。
page.php 看起来像这样:
<?php 
locate_template( 'page-home.php', true );
exit();
page-home.php 看起来像这样:
<?php get_header(); ?>
<?php get_template_part('template-sections/slider'); ?>
<?php get_template_part('template-sections/services'); ?>
<?php //etc. ?>
<?php get_footer();
header.php 看起来像这样:
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="profile" href="http://gmpg.org/xfn/11"/>
    <base href="<?php echo get_site_url(); ?>/">
    <?php wp_head(); ?>
</head>
<body itemprop="hasPart" itemscope="" itemtype="http://schema.org/WebPage" <?php body_class(); ?>>
<!-- etc -->
而且footer.php是这样的:
            <?php wp_footer(); ?>
    </main>
    <aside class="aside">
        <div class="aside__content">
        </div>
    </aside>
</div>
</body>
</html>
是的。有一个页面存在home于后端调用。我希望 Wordpress 选择该标题并将其用作header.php.
现在据我所知,Wordpress 通常会自动填充标题标签。那么这里有什么问题呢?谢谢!
PS:我没有wp_title在我的自定义 Wordpress 主题中的任何地方使用过滤器。
好的,我找到的解决方案可能会帮助其他人。所以我觉得可以把它贴在这里。
第 1 部分。与标准twentyseventeen主题的比较。我发现 Wordpress 需要add_theme_support( 'title-tag' );能够管理标题。(否则你应该<title>自己添加一个标签header.php,我猜。
第 2 部分。我需要添加一个自定义过滤器来functions.php以所需的格式显示标题。例如(使用 SEO 插件):
function custom_title( $title_parts ) {
    $page_id   = site_get_page_id(); // custom function, you might want to use global $post here
    $seo_title = @get_post_meta( $page_id, '_aioseop_title' );
    if ( isset( $seo_title[0] ) ) {
        $title = $seo_title[0];
    } elseif ( isset( $page_id ) ) {
        $title = get_the_title( $page_id );
    }
    $page_title           = isset( $title ) ? $title : 'Page not found in backend';
    $title_parts['title'] = $page_title;
    return $title_parts;
}
| 归档时间: | 
 | 
| 查看次数: | 2832 次 | 
| 最近记录: |