Autofill keywords from tags

#51312
Viewing 3 replies - 1 through 3 (of 3 total)
  • Todd
    Rank Math free

    Hello,

    Thanks for getting in touch with us.

    Here is some example code that you can use to update the focus keyword to be the tag you are using for the post:

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

    Add the code to your theme’s functions.php file.

    Please note that the page needs to be refreshed for the Rank Math tests to take effect and calculate the score.

    Looking forward to helping you. Thank you.

    Hello,

    thanks for the answer.
    Unfortunately this did not work.

    Just so that we don’t misunderstand each other:

    I want to put a keyword in the tags and automatically transfer it to the Focus Keyword. See the gif.

    [url=https://imgbb.com/][img]https://i.ibb.co/p1xZyXN/ezgif-com-optimize.gif[/img][/url]
    [url=https://imgbb.com/]miss png[/url]

    Greeting Heiko

    Alberto
    Rank Math business

    Hello,

    The code my colleague shared will get any current existing post, check its tags, and add it as each post’s focus keyword.

    What you are looking for is something that does that work meanwhile you are on that post, so it wouldn’t be a PHP code but a custom JS function.

    It is a feature not offered by Rank Math but if you need it, you could try to code it by yourself (or hire a coder to do it). It should be a JS that checks if the Tags input has any tag, and if it has, take the first one and add it to the Rank Math keywords input.

    Looking forward to help 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Autofill keywords from tags’ is closed to new replies.