Hello,
Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.
I assume you are trying to automatically add keywords to your product pages using this guide: https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/
Can you please check the individual product pages if the keywords are applied there?
If the issue persists, please share the code you are trying to implement here.
Looking forward to helping you.
Hello,
/**
* 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’ => -1,
‘post_type’ => ‘post’ // Replace post with the name of your post type
));
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’ );
The Code I added
Hello,
You need to change the post_type
to product
to add the focus keywords to your Products.
You can remove the previous code and add this one:
/**
* 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' => -1,
'post_type' => 'product' // Replace post with the name of your post type
));
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' );
I hope this helps.
Thank 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.