-
Hi
I tried the procedure described in your post :https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/
to automatically insert the missing focus keywords in the articles already present in my blog with the title of the post.
I inserted the rank-math.php file with the code you indicated inside the child theme folder but it does not work. In my articles without focus keyword the same does not appear.
I also tried to put the file in the parent theme but nothing.
Is there an alternative solution to this problem because i have 223 articles without focus keywords and doing it manually would take me a whole day…
Thanks.
P.S.
The code entered is as follows
/**
* 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 ticket ‘Automate the Insertion of Focus Keyword’ is closed to new replies.