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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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