Hello,
Thank you for contacting the support.
Assuming you’re saying that you want to use the first tag of each post as the focus keyword, please add the below code to the website and see if it gives you the desired output:
/**
* Function to automatically update the focus keyword with the post tags, if no focus keyword is set
*/
function update_focus_keywords()
{
$posts = get_posts(array(
'posts_per_page' => 100,
'post_type' => 'post' //replace post with the name of your post type
));
foreach ($posts as $p) {
$keywords = [];
$temp = [];
if (get_the_tags($p->ID)) {
foreach ((get_the_tags($p->ID)) as $tag) {
$temp[] = strtolower($tag->name);
$keywords[] = $temp[0];
}
if (!get_post_meta($p->ID, 'rank_math_focus_keyword', true)) {
update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords)));
}
}
}
}
add_action('init', 'update_focus_keywords');
You can follow this guide to add the code to the website:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how that goes.
Thank you.
According to your statement, the emphasis keyword for each post should be the first tag in each post. To test this, please insert the following code into your website and see if it produces the expected results.
You can use the following instructions to add the code to your website:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hello @zaidashraf,
Thank you for contacting our support.
We appreciate the input you shared. The URL guide should help guide the user to apply the code to the website.
@olayemibakare,
Please let us know if the code my colleague presented works on your end.
Looking forward to helping 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.