我嘗試更改存檔頁面上的標題,因為我使用它來列出自定義文章型別。事實上,我想洗掉頁面標題開頭的“存檔”文本。
我使用 wordpress 5.8 和一個來自二十二十個的自定義主題。
在我的 header.php 檔案中,有:
<?php wp_head(); ?>
但是當我將下面的代碼寫入我的functions.php.
remove_action('wp_head', '_wp_render_title_tag');
我也嘗試使用過濾器,但我沒有正確使用它,因為也沒有任何反應。
我怎樣才能做到這一點 ?
謝謝 !
uj5u.com熱心網友回復:
這個應該可以解決問題:
function change_archive_page_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'change_archive_page_title' );
將其添加到您的子主題 -> functions.php 編輯:它將頁面標題替換為空字串。
uj5u.com熱心網友回復:
要更改存檔標題,有幾種方法。一個人可能正在使用 SEO 插件?但是要以編程方式執行此操作,您可以使用過濾器get_the_archive_title
更改your_taxonomy為要修改顯示內容的分類法的名稱。
add_filter( 'get_the_archive_title', 'custom_archive_title', 10, 3 );
/**
* Change the archive title for a custom taxonomy
*
* @param string $title - The full archive Title
* @param string $original_title - The name of the archive without prefix.
* @param string $prefix - Prefix if set - otherwise "Archive"
* @return mixed
*/
function custom_archive_title( $title, $original_title, $prefix ) {
// Get the queried object - which would be the WP_Term.
$queried_object = get_queried_object();
// Check if it's your custom taxonomy
if ( 'your_taxonomy' === $queried_object->taxonomy ) {
// Remove the prefix.
$title = $original_title;
}
return $title;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/367203.html
標籤:php WordPress的 wordpress 主题
