我正在尝试创建完全自定义的页面,但是使用相同的功能在WP中创建页眉和页脚。我的页面上有这个
<?php
include("../wp-blog-header.php");
get_header();
?>
<title>My Custom Title Here</title>
<?php
wp_head();
get_footer();
?>
Run Code Online (Sandbox Code Playgroud)
页面显示一切正常,但是当我在页面源中将其作为标题添加<title>My Custom Title Here</title>后尝试添加get_header()时Page not found – My Custom Title
如何设置自定义页面标题?我的意思是页面加载后标题应该是<title>My Custom Title Here</title>
也许并不理想,但我在紧要关头做了以下事情。通过一些额外的逻辑,您可以将其添加到您的functions.php中,但如果您真的只需要它用于单个页面,我只需在调用之前将过滤器包含在该特定文件中get_header()。
<?php
include("../wp-blog-header.php");
add_filter( 'wp_title', 'custom_title', 1000 );
function custom_title($title) {
$title = 'My Custom Title Here';
return $title;
}
get_header();
?>
<?php wp_head(); get_footer(); ?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3071 次 |
| 最近记录: |