Focus keywords not saved

#19590
  • Resolved Ernesto Petros
    Rank Math free

    Greetings,
    I am trying to add focus keywords with this code, but nothing is saved (It works with other custom fields I have):

    add_action( ‘transition_post_status’, ‘add_keywords’, 10, 3 );

    function add_keywords( $new_status, $old_status, $post ){
    ……..
    ……..
    $post_ID=$post->ID;
    update_post_meta($post_ID, ‘rank_math_focus_keyword’, ‘test’);
    ……..
    ……..
    }

    Help please.

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

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Your code should be able to work. Could you please debug the output from your $post_id variable to check if it is returning the expected data?
    Please note that you can also hook into the following filter with slightly different logic and assign keywords to your posts:

    /**
     * Allow changing the meta keywords from the default Focus Keywords.
     *
     * @param string $keywords Keywords.
     */
    add_filter( 'rank_math/frontend/keywords', function( $keywords ) {
     return $keywords;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hi,
    The problem was with the variable value I was using as keyword. Sorted.
    Thank you

    Hello,

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

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

    If you do 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Focus keywords not saved’ is closed to new replies.