Placing the product title instead of the keyword. automatically

#944684
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello, we apologize for the issue you are facing with automatically setting the product title as the focus keyword.

    To achieve this, you can use the following code snippet in your rank-math.php file. This code will update the focus keyword with the product title only if no focus keyword is already set:

    /**
     * Function to automatically update the focus keyword with the product title, if no focus keyword is set
     */
    function update_product_focus_keywords() {
        $products = get_posts(array(
            'posts_per_page' => -1,
            'post_type' => 'product' // Replace product with the name of your post type
        ));
        foreach ($products 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_product_focus_keywords');

    Make sure to add this code in the correct location within your theme’s rank-math.php file. If you are using a code snippet plugin, ensure that it is set to run on the appropriate hooks (like init).

    If you continue to experience issues, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further. Thank you for raising this concern!

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

    Hello,

    You seemed to have marked this ticket as resolved.

    We’re just following up to know if you have any other concerns that we can assist you with. If your issue has been resolved, please let us know so we can mark this ticket as closed.

    Thank you for choosing Rank Math.

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

You must be logged in to reply to this ticket.