[英]How to remove the default meta title from functions.php in Wordpress?
Ok, so I have added my own title in the header.php好的,所以我在 header.php 中添加了自己的标题
<title>
<?php
if (!(is_front_page())) {
wp_title('', true,''); ?> (<?php the_time( 'Y/m/d' ); ?>)-
<?php }
echo get_bloginfo( 'name' ); ?>
</title>
It works great.它工作得很好。
The problem is that when I click on View Source, I see two title codes.问题是当我点击查看源代码时,我看到两个标题代码。
First one is my title that I manually added to header.php第一个是我手动添加到 header.php 的标题
And the second one is the default Wordpress title.而第二个是默认的 Wordpress 标题。
My question is, where do I need to modify (probably in the functions.php?) to remove the default Wordpress title?我的问题是,我需要在哪里修改(可能在函数中。php?)以删除默认的 Wordpress 标题?
Might be able to use this in your functions.php
based on: wp-includes/default-filters.php
可能可以在您的functions.php
中使用它。php 基于: wp-includes/default-filters.php
remove_action( 'wp_head', '_wp_render_title_tag' );
UPDATE更新
Based on your theme I recommend you remove your custom title from the header, remove the above remove_action
i previously suggested and use the below solution in your functions.php.根据您的主题,我建议您从 header 中删除您的自定义标题,删除我之前建议的上述remove_action
并在您的函数中使用以下解决方案。php。 this will hook into the existing theme title and modify its value using your custom title code:这将挂钩到现有的主题标题并使用您的自定义标题代码修改其值:
add_filter('wp_title', function($default_title){
$title = '';
if (!is_front_page()) {
$title .= wp_title('', false,'') .' '. get_the_time( 'Y/m/d' ) . '- ';
}
$title .= get_bloginfo( 'name' );
return $title;
});
Here's the working sulution.这是工作解决方案。 Just paste the below code to your functions.php:只需将以下代码粘贴到您的函数中即可。php:
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.