Focus keywords

#72635
  • Resolved David
    Rank Math free

    Hey

    I have searched high and low and been unable to find an answer.

    I am looking to get keywords automatically updated on any new posts submitted with frontend submit with the title of the post and tags.

    Unsure if this is possible but found the below codes but unsure if they are correct for my post.

    Thanks
    In advance for your help.

    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){
    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’ );

    Or

    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){
    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’ );

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Unfortunately there is no current feature/filter in Rank math to do so. You can use the following snippet that was used to auto-fill the keyword using tags. With the help of a developer, you can customize it to fit your situation.

    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){
    		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' );

    Please note that we recommend adding the keyword manually.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    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.

Viewing 1 replies (of 1 total)

The ticket ‘Focus keywords’ is closed to new replies.