Hello,
Thank you for contacting us and sorry for any inconvenience that might have been caused due to that.
You can try to use the following filter on your website to set the product title as a focus keyword only for the products that don’t have a keyword:
/**
* Function to automatically update the focus keyword with the product title, if no focus keyword is set
*/
function update_focus_keywords() {
$products = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'product' //replace post with the name of your post type
));
foreach ($products 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');
Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps and please don’t hesitate to let us know if you have any other questions.
Â
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.