Automate the Insertion of Focus Keyword

#922697
  • Resolved Gabrielet
    Rank Math free

    Hi
    I tried the procedure described in your post :

    https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/

    to automatically insert the missing focus keywords in the articles already present in my blog with the title of the post.

    I inserted the rank-math.php file with the code you indicated inside the child theme folder but it does not work. In my articles without focus keyword the same does not appear.

    I also tried to put the file in the parent theme but nothing.

    Is there an alternative solution to this problem because i have 223 articles without focus keywords and doing it manually would take me a whole day…

    Thanks.

    P.S.

    The code entered is as follows

    /**
    * 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’ );

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

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

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.

    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    Looking forward to helping you.

    Thank you.

    Gabrielet
    Rank Math free

    Ok, attached.

    Hello,

    We deeply apologize for the unexpected delay in response.

    We checked your website but unfortunately, the SFTP login you’ve shared is not working.

    However, we installed the Code Snippet plugin on your website and added the filter code. Now the focus keyword is automatically included in all of your posts.

    Hope that helps and please don’t hesitate to let us know if you have any other questions.
     
    Thank you.

    thanks. can i disable code snippets now? if you tell me where to insert the snippet i will insert it manually and delete the plugin. i hate having thousands of plugins on the site…..

    Hello,

    No, if you disable the Code Snippets plugin, the code will stop working because the code was installed using the Code Snippets plugin.

    If you want us to install the code natively in your child theme, then please share am SFTP credential that is working.

    Best regards,

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Ok, I changed the ftp accesses on sensitive data, it should work this time, can you insert the snippet natively please?

    Thanks!

    Hello,

    It appears the code has already worked because there are no longer posts in the dashboard with no focus keyword:

    Rank Math support

    Can you please confirm if you expect the code to work on other post type as well besides the regular article post type?

    With that said, we have gone ahead and still added the code to your theme’s functions.php file and tested it by creating an example post, and the keyword is automatically added.

    Looking forward to helping you.

    Thanks for the support, everything is perfect like this.

    Hello,

    We’re delighted to hear that this issue has been resolved. We appreciate your feedback.

    This ticket will be closed now, but if you ever have another question or need any help in the future, please don’t hesitate to create a new forum topic. We’ll be more than happy to assist you again.

    Thank you for choosing Rank Math and have a wonderful day!

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

The ticket ‘Automate the Insertion of Focus Keyword’ is closed to new replies.