How I can change all those in one time to set product title then website title i

#797274
  • salam petrol
    Rank Math free

    Hi

    How I can change all those in one time to set product title then website title in focus keyword for all ?

Viewing 1 replies (of 1 total)
  • Hello,

    To automatically set the product title and website title as the focus keyword for all your products, you can use a code snippet in your theme’s functions.php or rank-math.php file. Here is the code snippet you can use:

    /**
     * Function to automatically update the focus keyword with the product title and website title
     */
    function update_focus_keywords_all_products()
    {
        $products = get_posts(array(
            'posts_per_page' => -1,
            'post_type' => 'product'
        ));
        foreach ($products as $p) {
            $product_title = strtolower(get_the_title($p->ID));
            $website_title = get_bloginfo('name');
            $focus_keyword = $product_title . ' ' . $website_title;
            update_post_meta($p->ID, 'rank_math_focus_keyword', $focus_keyword);
        }
    }
    add_action('init', 'update_focus_keywords_all_products');

    Please note that this code will replace any existing focus keywords with the combination of the product title and website title for all your products. If you want to set the focus keyword only for products that don’t have any focus keyword set, you may need to modify the code accordingly.

    If you need further assistance or have any questions, feel free to reach out to our support team.

    Thank you for reaching out with your query!

    Sources:
    Why Can’t I Enter More Than 1 Focus Keyword in Post and Product Categories? » Rank Math
    How to Automate the Insertion of Focus Keyword » Rank Math
    Content Analysis Tests for Product Pages » Rank Math
    How to Enter SEO Meta Title, Description, and Focus Keyword » 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.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this ticket.