![](/img/trans.png)
[英]How to print page title of parent and up to one child only in WordPress
[英]WordPress Function to Change Child Page Title to Match Parent
我有一個WordPress網站,其中全局頁面模板(來自Elementor)為頁面提取正確的標題。
但是,對於我個人的WooCommerce產品(頁面),我只想將標題“產品”設置為頁面標題。 我正在尋找一個PHP或JS片段來替換任何“產品之子”頁面上的頁面標題。
謝謝!
看一下the_title
過濾器的文檔
你應該只能在父頁面ID中添加一個簡單的if
條件,這可能是這樣的嗎?
function replace_product_child_title( $title, $id = null ){
global $post; // Grab the current WP_Post object
$product_page_id = 12345; // Put the ID of your "Products" page here
// See if this post is a direct child of Products
if( $post->post_parent == $product_page_id ){
// If it is, override the title
$title = "PRODUCTS";
}
// Always return the title
return $title;
}
add_filter( 'the_title', 'replace_product_child_title', 10, 2 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.