automatikc keywords

#902205
  • Resolved charmeditalia
    Rank Math free

    Hi team, I am writing to you to ask for help on the code that automatically inserts keywords.
    The procedure I followed is the same as on your site and is the following:
    1) I created a rank-math.php file. This file was inserted inside the theme folder;
    2) I inserted this code inside the file

    /**
    * Function to automatically update the focus keyword with the post title, if no focus keyword is set
    */
    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){ // 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' );

    3) the example invites me to replicate the type_post, => ‘post’ with the name of my post.

    Now coming to the solution, what does Replace post with the name of your post type mean?
    the name of the page? the title of the post? What?

    Thank you.

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

    We apologize for the issue you are facing. Thank you for raising your concern regarding the code for automatically inserting keywords.

    In the code snippet you provided, the comment // Replace post with the name of your post type means that you should replace the word post with the actual name of your custom post type if you are using one. For example, if your custom post type is called portfolio, you would change it to:

    'post_type' => 'portfolio'

    If you are using the default post type, you can leave it as post. If you’re unsure about your post type name, you can check it in your WordPress dashboard under Posts or Custom Post Types.

    If you have any further questions or need additional assistance, please feel free to reply to this ticket, and a human agent from the Rank Math Support team will assist you further.

    Thank you for your understanding!

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

    I tried to add Home but the keywords don’t appear maybe I’m doing something wrong

    Problem solved.

    My site is in Italian

    When I purchased the theme the demo of this theme was in the original language (English) installing the Italian language therefore, the code did not detect the name of the modified language but the original one.

    In my opinion it is right to clarify with the code.

    Hello,

    We are glad that everything has been sorted out.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

The ticket ‘automatikc keywords’ is closed to new replies.