Hello,
Thank you for contacting Rank Math.
Please replace the code with this code:
add_shortcode('rm_keyword', 'rm_shortcode_focus_keyword');
function rm_shortcode_focus_keyword(){
global $post;
return RankMath\Post::get_meta( 'focus_keyword', $post->ID );
}
Once done, you can use the [rm_keyword] shortcode in the content.
Hope this helps.
Thank you.
Thanks for your help but it didn’t work.
Got this error
Hello,
You can switch the code to this one to get the desired result:
add_shortcode('rm_keyword', 'rm_shortcode_focus_keyword');
function rm_shortcode_focus_keyword() {
return get_post_meta(get_queried_object_id(), 'rank_math_focus_keyword', true);
}
Don’t hesitate to get in touch if you have any other questions.
I tried this code, but no luck.
Hello,
The code seems to be working fine on our local installation.
Please make sure that you are using the correct shortcode [rm_keyword] in the content.
You can record a screencast using loom.com showing how you have added the filter and how you are using the shortcode in the content so we can check.
We look forward to helping you.
Thanks for your support. I really appreciate it. The code is working now
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, 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.
Hello
The Focus Keyword Shortcode is working but all keywords showing. Only primary focus Keyword show code plz send me
Hello,
I have adjusted the code snippet to only show the primary focus keyword in the shortcode. Please replace the previous snippet with the one in the following pastebin link: https://pastebin.com/BXzJj1cF
Hope that helps. Please let us know if you have 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.