HI there,
Thanks for sharing your findings.
This code works as expected on my end, please ensure that you inspect the page source for your products and check the meta description:
/**
* Allow changing the meta description sentence from within the theme.
*
* @param string $description The description sentence.
*/
add_filter( 'rank_math/frontend/description', function( $description ) {
//this code will get the meta description from the WC product short description
global $product;
$description = $product->name." - "."Next Day Delivery";
return $description;
});
I hope this info helps.
Hello, that wont work i have 4000 different items….
All i want to do…. which i can do in yoast very easily
i have set – Rank Math> Titles > Products > Single Product Description =
%title% • Free Delivery & some more info •
Thats it.
In yoast i can add that in & all of my products update, new or old without having to go through and update every item…
In Rank Math, it only works with products added after using rankmath, the old ones do not update
Thanks
-
This reply was modified 5 years, 8 months ago by O A F O.
Hi there,
Thanks for this info.
I am sorry for this issue. I will pass this on to our dev team so that we can add this to our future development roadmap.
Feel free to reach out to us for any other questions in your next project or the current one.
Oh right… so that’s the end of that? 100% gutted spent weeks fine tuning… and then just that’s it….
I’ve tested a lot of plugins for seo & every single one has this option?
Can you just confirm to me what you think I need? I feel maybe you are not understanding it maybe?
As it should just be a thing built in…
If I update the title in rank math it updates all the titles… so why not the description?
Thanks
We are really sorry for the inconvenience.
We are working on it. In the meantime, please add this code to your theme’s functions.php file so that the meta description you set in your settings will be used even for your previous posts:
add_filter( 'rank_math/frontend/description', function( $description ) {
if ( is_singular( 'product' ) ) {
global $post;
$description = RankMath\Post::get_meta( 'description', $post->ID );
if ( '' !== $description ) {
return $description;
}
$value = RankMath\Helper::get_settings( 'titles.pt_product_description' );
$product = wc_get_product( $post->ID );
$value = str_replace( '%title%', $product->get_title(), $value );
$value = str_replace( '%wc_shortdesc%', $product->get_short_description(), $value );
return '' !== $value ? RankMath\Helper::replace_vars( $value, $product ) : '';
}
return $description;
});
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
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.