Frontend keyword

#693219
  • Hello ,

    I added to functions.php this code , but it doesnt work. I cleared cache from cloudflare and localy , i also tried to add it to rank-math.php but still no luck

    /**
    * Add <meta name=”keywords” content=”focus keywords”>.
    */
    add_filter( ‘rank_math/frontend/show_keywords’, ‘__return_true’);

    Also this one doesnt work too .

    /**
    * Function to automatically update the product focus keyword with the product category
    */
    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’);

    Thank you !

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

    I’m sorry to hear that you’re experiencing issues with the code you’ve added to your functions.php file. It seems like the code you’ve added is not working as expected, and you’ve also tried adding it to the rank-math.php file without success.

    The code you’ve shared is intended to automatically update the product focus keyword with the product category. However, it seems that the code might not be executing as expected.

    To further investigate this issue, I recommend checking for any error logs on your website that might provide more information about why the code isn’t working as intended. Additionally, please ensure that the code is added correctly and that there are no syntax errors.

    If you’re still encountering issues after checking these points, please assign this ticket to our support team using the available buttons, and we’ll be happy to assist you further.

    Thank you for bringing this to our attention!

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

    Hello issue solved.

    i used this code ,

    function update_focus_keywords() {
    $posts = get_posts(array(
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘product’ // 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’ );

    Hello,

    We are glad to hear that this issue has been resolved. Thank you for letting us know. This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.

    We appreciate your patience and cooperation throughout this process.

    Thank you for choosing Rank Math.

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

The ticket ‘Frontend keyword’ is closed to new replies.