【发布时间】:2019-04-09 18:41:10
【问题描述】:
我有一个 WordPress 网站,其中通过全局页面模板(来自 Elementor)提取页面的正确标题。
但是,对于我的个人 WooCommerce 产品(页面),我只想将标题“产品”设置为页面标题。我正在寻找一个 PHP 或 JS sn-p 来替换任何“产品的子级”页面上的页面标题。
谢谢!
【问题讨论】:
标签: javascript php wordpress
我有一个 WordPress 网站,其中通过全局页面模板(来自 Elementor)提取页面的正确标题。
但是,对于我的个人 WooCommerce 产品(页面),我只想将标题“产品”设置为页面标题。我正在寻找一个 PHP 或 JS sn-p 来替换任何“产品的子级”页面上的页面标题。
谢谢!
【问题讨论】:
标签: javascript php wordpress
查看the_title filter 的文档
您应该能够在其中使用父页面 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 );
【讨论】: