add_filter( 'the_title', 'custom_the_title' );
function custom_the_title( $title, $id ) {
global $product;
/*
* We use is_shop and is_product to check if the page is product archive
* or single product page. in_the_loop conditional is used to check if the loop
* is currently active, otherwise it will over write the page title as well
*/
if( ( is_shop() || is_product() ) && in_the_loop() ) {
$attr = $product->get_attributes();
// $attr contains the attribute array, apply the logic you need
// and set $title
return $title;
}
return $title;
}
1 回答
您需要使用
the_title
过滤器以及in_the_loop
,is_shop
和is_product
条件,如下所示 . 将以下代码添加到主题的functions.php文件中