Hello,
Thanks for contacting us.
You can use this code in your theme’s/child theme’s functions.php file to automatically use the post title as the focus keyword:
function update_focus_keywords() {
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post' //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' );
Hope this helps. Let us know if you need any further assistance.
Sorry but nothing changed.
Hello,
Thank you for getting back to us.
Could you kindly confirm with us if you want the title to be used as the focus keyword within the Posts or within your Pages?
The above code should work on your posts only. If you want to have this done on your WordPress pages then you can use this code (just modified it to assign the keyword to pages)
function update_focus_keywords() {
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'page' //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' );
Hope this helps. Please let us know if you have any other questions.
Thank you.
Hi there,
I want use it for Woocommerce Products
Ok it worked after modifying as product
Hello,
We are super happy that this resolved your issue. If you have any other questions, 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.