where to add the code snippet for focus keywords to function.php wordpress

#510570
Viewing 4 replies - 1 through 4 (of 4 total)
  • Bram
    Rank Math free

    I created a rank-math.php file and added it there, also with no results 🙁

    https://prnt.sc/ofuzf8BPaUw-

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    It seems that the Mercury theme is using a Custom Post type, that’s why the filter is not working. Could you please confirm? You can get in touch with their developer as well.

    If so, you may need to change this line in the filter with the post type name:

    'post_type' => 'post' //replace post with the name of your post type
    

    Meanwhile, Rank Math detects custom post types automatically and gives you the extra ability to configure title and meta settings. You can learn more about configuring titles and other settings by going through this article:
    https://rankmath.com/kb/new-post-type-detected/

    Let us know how this goes.

    Thank you.

    Bram
    Rank Math free

    There are indeed different post types:
    https://prnt.sc/X1u1oetDe9tI

    I edited the script:

    <?php 
    
    // add your custom code here
    
    /**
     * 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'	=> 1000,
        'post_type'		=> 'Games' // 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' );

    Would that be correct?

    Hello,

    You may set the post_type to “games” instead of “Games”.

    We hope that helps. We are here if you need us again.

    Thank you

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘where to add the code snippet for focus keywords to function.php wordpress’ is closed to new replies.