Focus Keyword

#705163
  • Resolved Anonymous
    Rank Math free

    How can i automatically use the product title as the Focus Keyword for products? So that I can change it on all products at once.

Viewing 1 replies (of 1 total)
  • Hello, I understand that you want to automatically use the product title as the Focus Keyword for your products. To achieve this, you can add the following code snippet to your theme’s functions.php or rank-math.php file:

    /**
     * Function to automatically update the focus keyword with the post title
     */
    function update_focus_keywords()
    {
        $posts = get_posts(array(
            'posts_per_page'    => -1,
            'post_type'        => 'product' //replace product with the name of your post type
        ));
        foreach ($posts as $p) {
            update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
        }
    }
    add_action('init', 'update_focus_keywords');

    Please note that this code will replace all your existing focus keywords. If you wish to set the post title as a focus keyword only for the products that don’t have a focus keyword set, then you may use a slightly modified version of the code.

    Once you’ve added the code, it will automatically update the focus keyword with the product title. Here’s a screenshot to guide you on where to add the code in the Theme File Editor:

    Navigate to Theme File Editor

    I hope this helps! If you have any further questions or need assistance with anything else, feel free to ask.

    Sources:
    How to Automate the Insertion of Focus Keyword » Rank Math
    Content Analysis Tests for Product Pages » Rank Math

    This is an automated reply from Rank Math Support Bot. If you need further assistance, please reply to this topic and a human support agent will reply to you shortly.

    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 Keyword’ is closed to new replies.