Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
I see that you want to display Product Short Description in Meta Description and limit it to 155 characters.
Regarding the length of Meta Description, the ideal length for a meta description is 160 characters. Google generally truncates them to ~ 155–160 characters. It’s a good practice to keep meta descriptions long enough so that they’re descriptive and hence we recommend writing meta descriptions between 50-160 characters.
Check out this knowledge article for further details on this – https://rankmath.com/kb/ideal-meta-description-length/
In case you want to set a fixed limit of 155 characters, please add this code in your theme’s functions.php
file – https://controlc.com/b7380088
Please note that the meta description length of 155 characters will not be visible in the editor. However, it will be applied and you can verify that in your page’s source code.
Hope this helps.
Looking forward to helping you. Thank you.
Thank you very much.
It works like a charm.
But I would like to limit on products only, I don’t want to limit on posts & pages meta description.
Can you please share the code to limit meta descriptions for posts, pages, products, product categories individually?
Thanks Again.
Hello,
Could you please add the below mentioned code to your theme’s functions.php
file in order to set a fixed limit of 155 characters for the products?
add_filter( 'rank_math/frontend/description', function( $description ) {
if(is_single() || is_product()){
return wp_html_excerpt($description, 155);
}
return $description;
});
You can further modify this condition for pages and posts as well.
Hope this helps.
Looking forward to helping you.
Thank you.
Thank you!
It worked.
I need to set custom limit for
1- products,
2- product category,
3- posts &
4- pages
can you please let me know the specific function?
Thanks
Hello,
1. For products, please add the above-mentioned custom code that I shared, to your functions.php
file.
2. For pages, please add the below-mentioned code:
add_filter( 'rank_math/frontend/description', function( $description ) {
if(is_single() || is_page()){
return wp_html_excerpt($description, 155); // Change 155 to number of characters that you wish to display
}
return $description;
});
3. For posts, please add the below-mentioned code:
add_filter( 'rank_math/frontend/description', function( $description ) {
if(is_single() ){
return wp_html_excerpt($description, 155);
}
return $description;
});
4. For product category, please add the below-mentioned code:
add_filter( 'rank_math/frontend/description', function( $description ) {
if(is_single() || is_product_category()){
return wp_html_excerpt($description, 155);
}
return $description;
});
Hope this helps.
Looking forward to helping you.
Thank you.
Hello,
We are super happy that we could address 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.