Add an automatic keyword for all posts/pages

#788865
  • Resolved Anonymous
    Rank Math free

    Hi do a particular site and I need to add keywords always the same for each post and pages.

    An example, the first post is called batman
    the keywords should create themselves automatically without me doing anything and should be: batman hero, batman super hero, batman villain, batman monster, batman best

    And if the second post is called superman the keywords will have to create themselves automatically without me doing anything and they will have to be: superman die, superman this is new hero, superman killing joker, superman the real hero, superman this is not a hero

    So each post must take the name of the page/post and must create the 5 keywords automatically

    I also talked to the bot but it can’t understand and keeps giving me individual pages and posts.

    How do I do that? Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    I apologize for the inconvenience you are facing. To automatically add keywords based on the post or page title in Rank Math, you can use a custom code snippet. This code will set the post title as the focus keyword if no focus keyword is already set.

    Here is the code snippet you can add to your theme’s functions.php or rank-math.php file:

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

    This code will automatically set the focus keyword based on the post or page title for each post/page. It will only set the keyword if no focus keyword is already defined.

    If you need further assistance or have any more questions, feel free to ask. Thank you for reaching out!

    Sources:
    How to Automate the Insertion of Focus Keyword » Rank Math
    How to Add Keywords to WordPress » Rank Math

    Hello,

    Thank you for contacting Rank Math support.

    We have a filter that helps you automate the insertion of focus keywords using the post title, category, and tags. https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/

    You can modify it further to add your desired focus keywords automatically. This will take some complex modification, which falls out of the scope of our support. If you’re not sure how to do it, you should hire a professional developer to help you with it.

    Please do not hesitate to let us know if you need our assistance with anything else.

    Anonymous
    Rank Math free

    This is only for the focus keyword, but then the other 4 keywords that I can put in how do I do it?

    Anonymous
    Rank Math free

    As not said solved

    Hello,

    You can use the code on the guide to automatically add a post title as the focus keyword. To achieve the use case you described, you will need to hire a developer to create a custom code using the filter we shared above.

    We hope this helps you resolve the issue. Don’t hesitate to contact us again with any other questions or concerns regarding Rank Math. We are always happy to help.

    Thank you for choosing Rank Math!

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

You must be logged in to reply to this ticket.