admin管理员组文章数量:1328615
I've added a filter to simplify product name on my shop page. This is the code I use
add_filter('the_title', 'mod_product__title', 10, 2);
function mod_product__title($title, $id) {
global $pagenow;
if ( $pagenow != 'edit.php' && get_post_type( $id ) == 'product' ) {
if(preg_match('/[^(:|.)]*/', $title, $matches)){
return trim($matches[0]);
}else{
return $title;
}
}
return $title;
}
As you can see here on the home page / If you click on "Keith Sonnier" you will see his full product name only on the product page.
Problem is : when I use a button to share the page by mail (contact button on the product page), the name of the page is the one simplified by the previous custom code.
Currently, I use this code to get the name of the page on the email
add_shortcode( 'custom_mailto_title', 'custom_mailto_title' );
function custom_mailto_title( $atts ) {
return esc_attr( get_the_title( get_the_ID() ) );
}
How Can I get the full name of the page with this button while keeping the product title simplified on the shop page?
Thanks!
I've added a filter to simplify product name on my shop page. This is the code I use
add_filter('the_title', 'mod_product__title', 10, 2);
function mod_product__title($title, $id) {
global $pagenow;
if ( $pagenow != 'edit.php' && get_post_type( $id ) == 'product' ) {
if(preg_match('/[^(:|.)]*/', $title, $matches)){
return trim($matches[0]);
}else{
return $title;
}
}
return $title;
}
As you can see here on the home page https://www.librairiedesarchives/ If you click on "Keith Sonnier" you will see his full product name only on the product page.
Problem is : when I use a button to share the page by mail (contact button on the product page), the name of the page is the one simplified by the previous custom code.
Currently, I use this code to get the name of the page on the email
add_shortcode( 'custom_mailto_title', 'custom_mailto_title' );
function custom_mailto_title( $atts ) {
return esc_attr( get_the_title( get_the_ID() ) );
}
How Can I get the full name of the page with this button while keeping the product title simplified on the shop page?
Thanks!
Share Improve this question asked Jul 29, 2020 at 15:13 PardaiglePardaigle 52 bronze badges1 Answer
Reset to default 0You can also get the title this way and avoid filters:
$title = get_post_field( 'post_title', $post_id, 'raw' );
本文标签: customizationHow to get the full product name by ignoring custom modification on it
版权声明:本文标题:customization - How to get the full product name by ignoring custom modification on it 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742223292a2435591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论