Hello,
Thank you for contacting us and we regret the inconvenience caused.
As you have a very high number of posts, the function can cause such issues.
To fix this, you can add an offset and define the number of posts to be processed at once and this should fix the issue.
Here’s a code that you can use to set the post title as the focus keyword with an offset value:
/**
* Function to automatically update the focus keyword with the post title, if no focus keyword is set
*/
function update_focus_keywords() {
$posts = get_posts(array(
'posts_per_page' => 1000,
'post_type' => 'post',
'offset' => 0 // Increase this by 1000 each time.
));
foreach($posts 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' );
Please make sure to remove the previously used code to add the focus keyword. Also, make sure to increase the offset value by 1000 each time you run the code.
The above function adds the focus keyword to 1000 posts at once (‘posts_per_page’ => 1000).
Please let us know how that goes.
Thank you.
Hello and thanks a lot for replying.
I will follow the guide and code but I have a question. What do you mean by increasing the offset every time I run the code? After I add the code into rank-math.php. How can I tell that the previous 1000 has finished and I am good to go with the next 1000?
In other words, how can I track the process?
Thanks a lot.
Hi again,
For some reason, I can’t see your previous reply?
Thanks.
Hello,
This function runs every time a page is reloaded in the backend so after saving the code just reload your posts page and then repeat the process by increasing the offset and reloading the posts page again.
You can change the offset values like this:
1st time : 'offset' => 0,
2nd time : 'offset' => 1000,
3rd time : 'offset' => 2000,
And so on...
Could you please try hard to refresh the page and see if the reply is visible?
Windows: CTRL + F5
Mac: Command + Shift + R
Looking forward to hearing back from you.
Thank you.
Hi again dear and thanks for reply.
I have tried the code above and everytime I try to execute it through:
Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.
Hello,
I tried to login into the cPanel using the credentials you’ve shared in the sensitive data section but the logins don’t seem to be working.
You can also try adding the code to your theme/child theme’s functions.php file or with the Code Snippets plugin. Here’s a guide regarding alternatives to add the code: https://rankmath.com/kb/wordpress-hooks-actions-filters/
If the issue persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.

It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping you.
Hello,
I have updated the sensitive data as requested. Can you please check further? For cPanel it’s 100%00 working and I’ve just tried to login with the same username and password.
Thank you.
Hello,
Now we can’t access the WordPress website backend, but all you need to do is add the code mentioned here: https://support.rankmath.com/ticket/adding-auto-add-focus-keywords-breaks-the-website/?view=all#post-331794
Then after the function runs one time you only need to update the entry that was mentioned in the previous reply.
Only the value you see in front of the offset should be changed and updated accordingly.
Don’t hesitate to get in touch if you have any other questions.
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.