Automatically Use the Post Title as the Focus Keyword

#329385
  • Resolved Devid
    Rank Math free

    Hi. Super Helpful Best Work Friends. Thanks a Lot.
    Bud Can You Help Me ? How can I write in this mode function “Three First Words Only from the Title ” to Fokus Keyword?:>>>>>>>>>>>>>>>>>
    ————————————————————————————————–
    /**
    * 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’ => ‘post’ //replace post 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’);

    —————————————————————————————————-

    Thank a Lot Friends.

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

    Thank you for contacting Rank Math and bringing your concern to our attention.

    Could you please try this filter to get the first three words from your title and set them as focus keywords?

    /**
     * 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'        => 'post' //replace post with the name of your post type
        ));
        foreach ($posts as $p) {
            $trimmed_title = wp_trim_words(strtolower(get_the_title($p->ID), 3, ''));
            update_post_meta($p->ID, 'rank_math_focus_keyword', $trimmed_title);
        }
    }
    add_action('init', 'update_focus_keywords');

    The filter should be added to your active theme’s functions.php file. Here’s another way to apply the filter using the rankmath.php file:
    https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php

    I hope that helps.

    Thank you.

    Devid
    Rank Math free

    Unforchunatly don’t work this filter in the rank math.php file.
    Help me friends , please.

    Hello,

    Please try this filter instead:

    function update_focus_keywords()
    {
        $posts = get_posts(array(
            'posts_per_page'    => -1,
            'post_type'        => 'post' //replace post with the name of your post type
        ));
        foreach ($posts as $p) {
            $trimmed_title = wp_trim_words(get_the_title($p->ID), 3, '');
            update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower($trimmed_title));
        }
    }
    add_action('init', 'update_focus_keywords');

    Let us know how that goes. Looking forward to helping you on this one.

    Devid
    Rank Math free

    You now is The Best Work in the World. Ewrestling work wery well. Yous Team and this plugin is Amazing – the Best in the World. I’m to do a site for Rank Math plugin.

    Thank a Lot my Friends.The Best Work in the World!

    Hello,

    You’re welcome.

    We are super happy that we have addressed your concern. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘Automatically Use the Post Title as the Focus Keyword’ is closed to new replies.