Hi there,
Thanks for contacting Rank Math support. We’re happy to help you with your focus keyword question.
We have a solution for you. You can use a filter code that we have created for this purpose. This filter code will loop through all your products and set the product name as the focus keyword for each product.
Here’s the code you need to add:
/**
* Function to automatically update the focus keyword with the product name
*/
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) {
update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
}
}
add_action('init', 'update_focus_keywords');
To add this code to your site, you can use one of these methods:
- Add it to your theme’s functions.php file or rank-math.php file. You can find these files in your WordPress dashboard > Appearance > Theme File Editor (for a Classic Theme) or WordPress Dashboard > Tools > Theme File Editor (for a Block Theme).
- Add it to a custom plugin or a code snippet plugin. You can use a plugin like Code Snippets to add the code easily.
You can learn more about how to add filter code to your site here: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Please try it and let us know if it worked for your goal.
Thank you for choosing Rank Math!
Thank you for your prompt help and support.
Works like a charm!
Hello,
We are super happy that this resolved 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.