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]);
            return $title;
    return $title;

As you can see here on the home page https://www.librairiedesarchives.com/ 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?


1 Answer 1


You can also get the title this way and avoid filters:

$title = get_post_field( 'post_title', $post_id, 'raw' ); 
  • Thanks! Can you just tell me where do I have tu put this line? Do I have to edit the function for the shortcode?
    – Pardaigle
    Commented Jul 30, 2020 at 9:57
  • Ok it seems to work with function custom_mailto_title( $atts ) { return esc_attr( get_post_field( 'post_title', $post_id, 'raw') ); } Thanks a lot :)
    – Pardaigle
    Commented Jul 30, 2020 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.