Hello,
To automatically set the product title and website title as the focus keyword for all your products, you can use a code snippet in your theme’s functions.php
or rank-math.php
file. Here is the code snippet you can use:
/**
* Function to automatically update the focus keyword with the product title and website title
*/
function update_focus_keywords_all_products()
{
$products = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'product'
));
foreach ($products as $p) {
$product_title = strtolower(get_the_title($p->ID));
$website_title = get_bloginfo('name');
$focus_keyword = $product_title . ' ' . $website_title;
update_post_meta($p->ID, 'rank_math_focus_keyword', $focus_keyword);
}
}
add_action('init', 'update_focus_keywords_all_products');
Please note that this code will replace any existing focus keywords with the combination of the product title and website title for all your products. If you want to set the focus keyword only for products that don’t have any focus keyword set, you may need to modify the code accordingly.
If you need further assistance or have any questions, feel free to reach out to our support team.
Thank you for reaching out with your query!
Sources:
Why Can’t I Enter More Than 1 Focus Keyword in Post and Product Categories? » Rank Math
How to Automate the Insertion of Focus Keyword » Rank Math
Content Analysis Tests for Product Pages » Rank Math
How to Enter SEO Meta Title, Description, and Focus Keyword » Rank Math
This is an automated reply from Rank Math Support Bot. If you need further assistance, please reply to this topic and a human support agent will reply to you shortly.
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.