Product description

#701129
  • Hello everyone,
    I face a problem and i want your help.

    Products has 2 descriptions. Short description and product description
    Rank math automatically collects short description for excerpt.
    How to reverse that and take the products description instead ?

    Thank you.

    this code is not working :

    /**
    * 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 = RankMathPost::get_meta( ‘description’, $post->ID );

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

    return $description;
    });

Viewing 15 replies - 1 through 15 (of 19 total)
  • Hello,

    We apologize for the inconvenience you’re experiencing with the product descriptions. To reverse the priority of the product descriptions, you can use a filter to override the order of priority and make the product description the meta description for all your products.

    Here’s the filter you can use:

    /**
     * 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 = RankMathPost::get_meta( 'description', $post->ID );
    
     if ( is_product()) {
     $desc = RankMathHelper::get_settings( "titles.pt_{$post->post_type}_description" );
     if ( $desc ) {
     return RankMathHelper::replace_vars( $desc, $post );
     }
     }
    
     return $description;
    });

    Once you’ve added this filter, the product description will be used as your meta description, even when a higher priority description is available.

    If you need further assistance or have any other questions, feel free to ask. We’re here to help!

    Thank you for reaching out to us!

    Sources:
    How to Set Product Meta Description Using Rank Math » Rank Math
    Using Variables in the SEO Title and Description » Rank Math

    I get an error ,

     PHP code changes were not applied due to an error on line 422 of file wp-content/themes/woodmart-child/functions.php. Please fix and try saving again.
    
    Uncaught Error: Class "RankMathPost" not found in wp-content/themes/woodmart-child/functions.php:422
    Stack trace:
    #0 wp-includes/class-wp-hook.php(324): {closure}()
    #1 wp-includes/plugin.php(256): WP_Hook->apply_filters()
    #2 wp-content/plugins/seo-by-rank-math/includes/traits/class-hooker.php(102): apply_filters_ref_array()
    #3 wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php(193): RankMath\Paper\Paper->do_filter()
    #4 wp-content/plugins/seo-by-rank-math/includes/frontend/class-head.php(201): RankMath\Paper\Paper->get_description()
    #5 wp-includes/class-wp-hook.php(324): RankMath\Frontend\Head->metadesc()
    #6 wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #7 wp-includes/plugin.php(565): WP_Hook->do_action()
    #8 wp-content/plugins/seo-by-rank-math/includes/traits/class-hooker.php(88): do_action_ref_array()
    #9 wp-content/plugins/seo-by-rank-math/includes/frontend/class-head.php(172): RankMath\Frontend\Head->do_action()
    #10 wp-includes/class-wp-hook.php(324): RankMath\Frontend\Head->head()
    #11 wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #12 wp-includes/plugin.php(517): WP_Hook->do_action()
    #13 wp-includes/general-template.php(3052): do_action()
    #14 wp-content/themes/woodmart-child/header.php(20): wp_head()
    #15 wp-includes/template.php(790): require_once('/home/shopiogr/...')
    #16 wp-includes/template.php(725): load_template()
    #17 wp-includes/general-template.php(48): locate_template()
    #18 wp-content/themes/woodmart/page.php(13): get_header()
    #19 wp-includes/template-loader.php(106): include('/home/shopiogr/...')
    #20 wp-blog-header.php(19): require_once('/home/shopiogr/...')
    #21 index.php(17): require('/home/shopiogr/...')
    #22 {main}
      thrown
    Dismiss

    Hello,

    Apologies for the confusion.

    To get the full product description to the meta description, you can use the following filter to create a variable called %woo_full_desc% that can be used in the snippet editor:

    add_action( 'rank_math/vars/register_extra_replacements', function() {
    	rank_math_register_var_replacement(
    		'woo_full_desc',
    		[
    			'name'        => esc_html__( 'Woo Full Desc.', 'rank-math' ),
    			'description' => esc_html__( 'Woo Full Description...', 'rank-math' ),
    			'variable'    => 'woo_full_desc',
    			'example'     => woo_full_desc_callback(),
    		],
    		'woo_full_desc_callback'
    	);
    } );
    function woo_full_desc_callback() {
    	global $post;
    	if ( empty( $post ) ) {
    		return 'Product Description';
    	}
    
    	return wp_strip_all_tags( $post->post_content );
    }

    Once done, you can use %woo_full_desc% in the meta description so it won’t result in the product short description.

    Also, if you’re getting an error when inserting the filter into your theme’s functions.php, please use the other methods mentioned here:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Hello again,
    If i edit a product and add the %woo_full_desc% it works.
    If i add the %woo_full_desc% on titles&meta > products , it doesnt.
    i Have 1000 products? Do i have to add it on every single one ?
    + can i limit it to 160 char ?

    Thank you.

    Hello,

    To help you investigate this issue, we might need to take a closer look at your website and settings. Please follow these steps:

    • Edit the first post on this ticket and include your WordPress and FTP logins in the Sensitive Data section. This is a secure section that only our support staff can access.
      Sensitive Data Section
    • Make sure you take a complete backup of your website before sharing the information with us.
    • If you prefer, you can use this plugin to generate a temporary login URL to your website and share that with us instead: https://wordpress.org/plugins/temporary-login-without-password/
    • You can also use this plugin to monitor what changes our staff might make on your website (if any): https://wordpress.org/plugins/wp-security-audit-log/

    We appreciate your cooperation and patience. Thank you for choosing Rank Math.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    We modified the filter on your website to limit 160 characters in the description. However, regarding the %woo_full_desc% variable in Rank Math > Titles & Meta, we will need your FTP logins to check the issue further.

    In this case, please edit the first post on this ticket again and include your FTP logins in the sensitive data section.

    Looking forward to helping you.

    Thank you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hey again ,
    on schema markup , descriptions are working as I can see. but not on google .
    I found a bug , if someone can say it like this.
    if description cut off in the middle of a word , it adds a ?
    if the it cuts the sentence completed , its ok .
    I will attach 2 screenshots to check. Can somehow add three dots at the end ? instead of ?

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

    1. Content from the 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 (long description)

    In case you want to force the actual global settings to take precedence you would need to add the following filter on your website:

    
    /**
     * 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 ( is_product()) {
     $desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
     if ( $desc ) {
     return RankMath\Helper::replace_vars( $desc, $post );
     }
     }
    
     return $description;
    });
    

    To apply the filter you can use one of the following methods: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    As for the limit to the callback function for the meta description, please update the callback with the following:

    
    function woo_full_desc_callback() {
    	global $post;
    	if ( empty( $post ) ) {
    		return 'Product Description';
    	}
    	return mb_strimwidth( wp_strip_all_tags( $post->post_content ), 160, '...', 'UTF-8' );
    }
    

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,
    i’ve added the function you shared , but I get no description.

    Thank you.

    image

    https://imgur.com/a/G5fu4GZ

    Hello,

    We checked the product, and the meta description is being added correctly to the products:

    You can also confirm that using the following tool: https://rankmath.com/tools/meta-tag-analyzer/

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

    I dont think you understand.
    As I said in the 1st post , I dont want the short description.
    I want the product description to show.
    The function that the guy above you, gave me , didn’t work and I had to remove it. it is a production site. Right now I dont have any function added.
    You asked me access and I gave you one to solve it , as you said.
    5 Guys here , says different things.

    I want the product description limited to 160char to show on meta description and schema markup.

    add_action( 'rank_math/vars/register_extra_replacements', function() {
    	rank_math_register_var_replacement(
    		'woo_full_desc',
    		[
    			'name'        => esc_html__( 'Woo Full Desc.', 'rank-math' ),
    			'description' => esc_html__( 'Woo Full Description...', 'rank-math' ),
    			'variable'    => 'woo_full_desc',
    			'example'     => woo_full_desc_callback(),
    		],
    		'woo_full_desc_callback'
    	);
    } );
    function woo_full_desc_callback() {
    	global $post;
    	if ( empty( $post ) ) {
    		return 'Product Description';
    	}
    
    	return wp_strip_all_tags( $post->post_content );
    }

    Above function works only , if I edit 1 by 1 product and add the %woo_full_desc% .
    I have 1000 products , and soon will be more. I want to add the above code to titles&meta -> products and change the description to all of them .

    Please read the conversation before answer.

    Thank you appreciate your time.

    Hello,

    Apologize for the inconvenience. We checked your website and we found that you only added the callback function on your website. However, we modified the filter on your functions.php file and now Rank Math is generating the meta description for your products properly.

    Hope that helps and please don’t hesitate to let us know if you have any other questions.
     
    Thank you.

    Hello again ,

    Thank you for the code. it works in terms of the correct description .
    Thanks again. I like it. !
    1 issue i discovered , i saw that you set maximum at 150 words and to stop at the last space.
    But , it stops in the first line of the description. Even if it has some spaces ahead before the 150 words threshold.

    I will attach a screenshot for reference.


    https://imgur.com/a/MPH3grX

    Is it possible to take a look at it again ?

    Thank you !

Viewing 15 replies - 1 through 15 (of 19 total)

The ticket ‘Product description’ is closed to new replies.