Use Product Description Meta from Settings Instead of Excerpt

#31434
  • Resolved Daniel
    Rank Math free

    Hi there,

    i have searched the forum and found few similar requests. Tried them all, but none of it worked.
    I want product description Meta to ignore excerpt and use whatever is setup in title and meta product description settings for all existing products please.

    I’m not sure why RankMath prefers excerpt instead of what is defined in the Product Title settings for Products.

    It is working as I would expect for product categories, they all have the descriptions, and rankmath is correctly using what is prefilled in title & meta product category settings. I would like it to work the same for the product descriptions please.

    Many thanks

    Custom function welcome.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Todd
    Rank Math free

    Hi Danie,

    Thanks for getting in touch with us.

    This is the order we follow to generate meta descriptions for WooCommerce product:

    1. Content from SEO Description field
    If that is missing, then:
    2. WooCommerce Excerpt or Product Short Description
    If that is missing, then:
    3. Template From General Settings in WordPress Dashboard > Rank Math > Titles & Meta > Products
    If that is missing, then:
    4. Auto generated Content from the product page

    If you want to show the auto generated description from the content ( step 4 ) then, please add the code which we provided here:

    https://wordpress.org/support/topic/make-excerpt-pull-from-product-description-instead-of-short-description/#post-12358847

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Daniel
    Rank Math free

    Thank you for your reply.

    I would prefer Option 3 instead of 2 for product pages only

    I found this:
    3. Use the Description from Global Setting, if the description is missing in the Post metabox:
    /**
    * Use the Description from Global Setting, if the description is missing in the Post metabox
    */
    add_action( ‘rank_math/frontend/description’, function( $description ) {
    global $post;
    $desc = RankMath\Post::get_meta( ‘description’, $post->ID );

    if ( ! $desc ) {
    $desc = RankMath\Helper::get_settings( “titles.pt_{$post->post_type}_description” );
    if ( $desc ) {
    return RankMath\Helper::replace_vars( $desc, $post );
    }
    }

    return $description;
    });

    The problem with this is, that it pulls product description from global settings into products, product categories, posts as well !! Can it be edited so it only pulls into products descriptions please.

    Todd
    Rank Math free

    Hello Daniel,

    Here is the code that will only work for products:

    /**
     * Use the Description from Global Setting, if the description is missing in the Post metabox
     */
    add_action( 'rank_math/frontend/description', function( $generated ) {
        global $post;
        if ( 'product' !== $post->post_type ) {
            return $generated;
        }
        $desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
        $desc = RankMath\Helper::replace_vars( $desc, $post );
        return empty( $desc ) ? $generated : $desc;
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    This code does not work. I also need ONLY the post type “product” to pull the meta description from General Settings in WordPress Dashboard > Rank Math > Titles & Meta > Products.

    With your code the other post types like product category, ends up with the meta description from the first item on the page.

    Can you please correct it?

    Hello,

    Please replace the code with the following:

    
    add_action( 'rank_math/frontend/description', function( $generated ) {
    	if ( ! is_product() ) {
    		return $generated;
    	}
    
    	global $post;
    	$desc = RankMath\Helper::get_settings( "titles.pt_product_description" );
    	$desc = RankMath\Helper::replace_vars( $desc, $post );
    	return empty( $desc ) ? $generated : $desc;
    });
    

    This should fix the issue.

    • This reply was modified 4 years, 2 months ago by Pratik.
    Daniel
    Rank Math free

    Looks like it’s working as it should.. Nice one!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘Use Product Description Meta from Settings Instead of Excerpt’ is closed to new replies.