Focus Keyword auto-insert problem

#142261
  • Resolved Nuri Eleman
    Rank Math free

    Hi, I’ve tried it with the code that you shared earlier, but it added to all my posts.

    My goal is to automatically add words from the tag or topic title as focus keyword for each post.

    keyword1

    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 2 replies - 1 through 2 (of 2 total)
  • Roel John
    Rank Math business

    Hello,

    The code is working fine on our end. Maybe you need to customize a little bit based on your site requirements. Unfortunately, Rank Math really doesn’t have this kind of feature so you need to create a WordPress functionality to achieve this.

    I hope that helps. If you require any further assistance don’t hesitate to get in touch again.

    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.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Focus Keyword auto-insert problem’ is closed to new replies.