-
Hi
I would like to add the WooCommerce Single products description to Variables. Single Product Description: %excerpt% replace Single Product Description. so is it possible?
I also like to add the auto Focus Keyword.
-
Hello,
Thank you for contacting us.
I’m not sure whether I fully understand the question. However, 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 pageIf you wish to give more preference to the description set in Titles & Meta > Products, then you can add the below code in your theme’s
functions.php
file: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; });
You can also follow this guide to add the code:
https://rankmath.com/kb/wordpress-hooks-actions-filters/For automating the insertion of focus keyword, please follow this guide:
https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/Hope this helps.
Thank you.
HI
Thanks for your replay
I have added the following codes in the functions.php file.
but I do not see any WooCommerce Excerpt Variables, please suggest to mealso, I would like to use the product title in the Focus Keyword.
Thanks, sir
i checked this > WordPress Dashboard > Rank Math > Titles & Meta > Products > Single Product Description. but I do not see any WooCommerce Excerpt Variables
Hello,
Could you please confirm if you wanted to use your product’s long description for your meta description?
If so, you can create a custom variable for the product’s long description by adding this filter on your site:
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 ); }
After this, you can use the
%woo_full_desc%
variable in the SEO description or single product description field.Please note that the filter may not be visible while editing the products as it only works when your products load in a browser. You can check the published/saved product’s meta description via its source code.
You can also check the product’s meta description using this tool:
https://www.heymeta.com/I hope that helps.
Thank you.
i would like to display product 160 characters description
Thanks
Hello,
To use the description from the global settings, you will also need to use the filter provided by my colleague here: https://support.rankmath.com/ticket/add-variables-in-the-woocommerce-single-products-description/?view=all#post-307879
If you are using both filters and still the description is showing the short description then we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.
It is completely secure and only our support staff has access to that section. If you want, you can use the below 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 use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping you.
HI I am going to send you my login info
so please check and please help mei will send it Sensitive Data section
Thanks
HI do you have any update?
Hello,
The filter is indeed working but it seems to Rank Math’s SEO settings in your individual product is not honoring the product’s global meta settings.
Allow me to check this one with our dev team. You should hear from us shortly.
Looking forward to helping you.
Hello,
The settings from the Titles & Meta settings are the third on the list and as such, we added the filter shared initially by our colleague to make sure that the settings there take precedence.
If you check the products description now on the front end you’ll see the correct settings being applied.
Don’t hesitate to get in touch if you have any other questions.
Thanks for your help
For the last question, I would like to add the product’s title in the Focus Keyword. i mean, auto add the product’s title in the Focus Keyword
is it possible?Hello,
Yes, you can add the below filter to automate the focus keyword insertion with product title:
/** * Function to automatically update the focus keyword with the post title, if no focus keyword is set */ function update_focus_keywords() { $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'product' // Replace post with the name of your post type )); foreach($posts as $p){ // Checks if Rank Math keyword already exists and only updates if it doesn't have it $rank_math_keyword = get_post_meta( $p->ID, 'rank_math_focus_keyword', true ); if ( ! $rank_math_keyword ){ update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID))); } } } add_action( 'init', 'update_focus_keywords' );
The above code would use the product title as the focus keyword for the products that are missing the focus keywords.
Let us know how that goes.
Thank you.
thanks
These functions will replace the product title with the Focus Keyword? or these will replace pages Focus Keyword/ posts Focus Keyword?thanks
Hello,
That code would use the Product title as the focus keyword for the Products that are missing the focus keywords.
Hope this helps.
Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.
The ticket ‘add Variables in the WooCommerce Single products description’ is closed to new replies.