-
I put the code in the rank-math.php file but the tags are not added as a keyword
-
Hello, we apologize for the issue you are facing with the focus keywords not being set from the tags. To ensure that the code works correctly, please double-check that you have added the following code snippet to your
rank-math.php
file:/** * Function to automatically update the focus keyword with the post tags */ 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 = []; if (get_the_tags($p->ID)) { foreach ((get_the_tags($p->ID)) as $tag) { $keywords[] = strtolower($tag->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords))); } } } add_action('init', 'update_focus_keywords');
Make sure that you have saved the changes after adding the code. Additionally, check if there are any caching plugins active that might be preventing the changes from taking effect. If everything seems correct and it still doesn’t work, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.
Thank you for raising this concern!
I put the code in the rank-math.php file but the tags are not added as a keyword
Hello,
In this case, 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/
Looking forward to helping you.
Thank you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hello,
We checked your website but were not able to find any posts there:
Can you please confirm if you want to use this further for other post types? If so, you’ll have to change the post_type name in the filter:
'post_type' => 'post' //replace post with the name of your post type
Let us know how it goes. Looking forward to helping you.
I need product tags to be created with keywords
Hello,
Since you’re working on products, you may need to update the
get_the_tags
andtags
in the filter.We have updated the filter on your site to this one to automate the product tags to be the keywords for your products:
function update_product_focus_keywords() { $products = get_posts(array( 'posts_per_page' => 100, 'post_type' => 'product' //replace post with the name of your post type )); foreach ($products as $p) { $keywords = []; if (get_the_terms($p->ID, 'product_tag')) { foreach(get_the_terms($p->ID, 'product_tag') as $term) { $keywords[] = strtolower($term->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords))); } } } add_action('init', 'update_product_focus_keywords');
Hope that helps.
Thank you. Everything works
Hello,
We are glad that everything has been sorted out.
Do you still need our assistance with anything else or can we go ahead to close the ticket?
We look forward to hearing from you.
Thank you.
Problem solved
Hello,
We are glad to know that this issue has been resolved. Thank you for letting us know.
This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.
We appreciate your patience and cooperation throughout this process.
Thank you for choosing Rank Math.
The ticket ‘Automatically Use the Tags as the Focus Keyword’ is closed to new replies.