How to auto setup focus keyword as tag title

#41636
  • Resolved Raghu M
    Rank Math free

    Hi, may in know-how to auto set up focus keywords as my tag’s tile as I have more growing tags so updating manually is difficult, awaiting for a reply.

    • This topic was modified 4 years, 8 months ago by Raghu M.
Viewing 15 replies - 1 through 15 (of 21 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Could you please test the code snippet on this page and let us know if it does the trick for you:
    https://support.rankmath.com/ticket/convert-tags-into-keywords/?view=all

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hi Michael, thanks for your earliest reply I just followed the instructions as mentioned in the link but even after copying the code to functions.php file things didn’t work for and also I have attached the video link of what I did, please go through the same and let me know if I had been wrong and can also share wp login details for your further analysis. thanks

    https://www.loom.com/share/a78b60de253e448ca0515a20f2c26004

    Hi there,

    Thanks for the follow up.

    I think that I might not have understood your initial request. Do you want to set the SEO title from the focus keyword set or you would like the focus keyword to be generated from the tag title?

    We are looking forward to helping you. Thank you.

    Hi we like the focus keyword to be generated from the tag title. Thanks

    Hello,

    Thank you for contacting Rank Math today.

    Here is some example code that you can use to update the current term name being edited as the focus keyword:

    /*
     * 
     * A snippet to get the current term being edited and set it as the 
     * the Rank Math focus keyword
     * 
     */
    add_action( 'admin_init', 'custom_tags_feature' );
    function custom_tags_feature(){
    	global $taxnow;
    
        if ( ! $taxnow || empty( $_GET['tag_ID'] ) ) {
        return null;
        }
    
        $term_id = absint( $_GET['tag_ID'] );
        $term = get_term( $term_id, $taxnow );
    	update_term_meta($term_id,'rank_math_focus_keyword',$term->name);
    	
    }

    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.

    ​​​​​​

    Hi Good Morning, could you please let me know in which .php file i need to place this code to achieve the results.

    Hi I tried adding the above-mentioned code to the bottom of my functions.php file then after checked tags but focus keyword was not updated as tag’s title

    Hi Raghu,

    Thanks for the follow up.

    As I mentioned, you need to resave the tag page for the changes to take effect and for Rank Math to calculate the tests score.

    Please try this and let us know how this goes. Thank you.

    Hi Michael DavisGood Morning,

    Thanks for your help, the code you provided last day, it worked for me so the latest update is I can see focus keyword fetting updates as title/term value for tag’s and categories as well, thank you very much.

    And one more help, can you please help me with a similar kind for code for posts as well. thanks

    HI Raghu,

    Thanks for the follow up.

    I am glad that the first code is now working πŸ™‚

    Would you like the focus keyword to be generated from the primary taxonomy when editing the post? A post can also have several categories selected, would you like the keywords to fallback to all these or just the primary term?

    We are looking forward to helping you. Thank you.

    Hi as of now am just looking for primary term ( post title ) to be as focus keyword.

    Thanks

    I am also looking for the same, as i imported post in bulk but they haven’t keywords.

    Hello,

    Thanks for the follow up.

    You can add the to your theme’s functions.php file to loop through your posts and update the focus keyword:

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

    You would need to delete this code after the keywords have been updated. Please perform a backup before using this code since it will replace the keywords assigned to posts. Let us know how it goes.

    I hope this info helps. Thank you.

    Hi good morning, thanks for update and will keep you posted.

    Todd
    Rank Math free

    Hi Raghu,

    Sounds good.

    If you need help with anything else, please open a new support ticket here so we can help.

    We are always here for assistance.

    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 15 replies - 1 through 15 (of 21 total)

The ticket ‘How to auto setup focus keyword as tag title’ is closed to new replies.