• Resolved specter33

    (@specter33)


    Automatically Use the “Product Title” as the Focus Keyword?
    I found the following code snippet on your site that uses categories, but I don’t know how to change it to include the title in the focus keyword.

    function update_product_focus_keywords()
    {
    $products = get_posts(array(
    ‘posts_per_page’ => 100,
    ‘post_type’ => ‘product’ //replace post with the name of your post type
    ));
    foreach ($products as $p) {
    $keywords = [];
    if (get_the_terms($p->ID, ‘product_cat’)) {
    foreach(get_the_terms($p->ID, ‘product_cat’) as $term) {
    $keywords[] = strtolower($term->name);
    }
    update_post_meta($p->ID, ‘rank_math_focus_keyword’, implode(“, “, array_unique($keywords)));
    }
    }
    }
    add_action(‘init’, ‘update_product_focus_keywords’);`

Viewing 1 replies (of 1 total)
  • Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @specter33,

    Thank you for contacting support.

    You can modify that filter to something like this to update the products focus keyword to be the title:

    
    function update_product_focus_keywords()
    {
    $products = get_posts(array(
    'posts_per_page' => 100,
    'post_type' => 'product' //replace post with the name of your post type
    ));
    foreach ($products as $p) {
    update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
    }
    }
    add_action('init', 'update_product_focus_keywords');
    

    Don’t hesitate to get in touch if you have any other questions.

Viewing 1 replies (of 1 total)
  • The topic ‘Automatically Use the Product Title as the Focus Keyword’ is closed to new replies.