How to get the full product name by ignoring custom modification on it

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.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?

Thanks!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

$title = get_post_field( 'post_title', $post_id, 'raw' );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x