[英]How to remove the default meta title from functions.php in Wordpress?
好的,所以我在 header.php 中添加了自己的標題
<title>
<?php
if (!(is_front_page())) {
wp_title('', true,''); ?> (<?php the_time( 'Y/m/d' ); ?>)-
<?php }
echo get_bloginfo( 'name' ); ?>
</title>
它工作得很好。
問題是當我點擊查看源代碼時,我看到兩個標題代碼。
第一個是我手動添加到 header.php 的標題
而第二個是默認的 Wordpress 標題。
我的問題是,我需要在哪里修改(可能在函數中。php?)以刪除默認的 Wordpress 標題?
可能可以在您的functions.php
中使用它。php 基於: wp-includes/default-filters.php
remove_action( 'wp_head', '_wp_render_title_tag' );
更新
根據您的主題,我建議您從 header 中刪除您的自定義標題,刪除我之前建議的上述remove_action
並在您的函數中使用以下解決方案。php。 這將掛鈎到現有的主題標題並使用您的自定義標題代碼修改其值:
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;
});
這是工作解決方案。 只需將以下代碼粘貼到您的函數中即可。php:
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.