我使用下面的代码自动缩短静态主页主store 、类别和标签页面上的WooCommerce产品标题.我也想为相关产品做同样的事情.我应该在这里为相关产品添加什么条件标签
此代码自动将静态主页主store 、类别和标签页面上的WooCommerce产品标题缩短为设置的字符数
function short_woocommerce_product_titles_chars( $title, $id ) {
if ( ( is_front_page() || is_shop() || is_product_tag() || is_product_category() ) && get_post_type( $id ) === 'product' ) {
// Kicks in if the product title is longer than 60 characters
if ( strlen( $title ) > 60) {
// Shortens it to 60 characters and adds ellipsis at the end
return substr( $title, 0, 60 ) . '...';
}
}
return $title;
}
add_filter( 'the_title', 'short_woocommerce_product_titles_chars', 10, 2 );