How to add listing title as focus keyword

#1004050
  • Resolved Shiniya K
    Rank Math free

    I am using the “My Listing” theme. and for all listings using a subdomain (using the Subdomain Pro plugin). How can I make each listing’s title the focus keyword automatically?
    I need to update the existing listings and newly adding listings focus keyword to the title of the listing

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

    I apologize for the issue you are facing. To automatically set each listing’s title as the focus keyword in your "My Listing" theme, you can add a custom code snippet to your theme’s rank-math.php file. This will ensure that both existing and newly added listings have their titles set as focus keywords.

    Here’s a code snippet you can use:

    /**
     * Function to automatically update the focus keyword with the listing title
     */
    function update_focus_keywords() {
        $posts = get_posts(array(
            'posts_per_page' => -1,
            'post_type' => 'listing' // Replace 'listing' with the actual post type for your listings
        ));
        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');

    Instructions:

    1. Navigate to WordPress Dashboard → Appearance → Theme File Editor (for a Classic Theme) or WordPress Dashboard → Tools → Theme File Editor (for a Block Theme).
    2. Open the rank-math.php file.
    3. Add the above code snippet to the file.
    4. Click Update File to save your changes.

    Important Note:

    • Make sure to replace 'listing' in the code with the actual post type name used by your "My Listing" theme if it differs.
    • This code will replace any existing focus keywords with the listing titles. If you want to set the title as a focus keyword only for listings that don’t have a focus keyword set, let me know, and I can provide an alternative snippet.

    If you encounter any issues or need further assistance, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.

    Thank you for raising this concern!

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

    May i add the code using code snippet plugin? Or it mandatory to add in the rank-math.php?

    May i add the code using code snippet plugin?

    i am using subdomain for lylistings. is this code will work for subdomain?

    i am blocked?

    Hello,

    We deeply apologize for the unexpected delay in response.

    Please note that Rank Math counts your subdomain as an individual site so you’ll have to add the filter code in all of them.

    However, you can use any of the methods mentioned here to add the code to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    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 6 replies - 1 through 6 (of 6 total)

The ticket ‘How to add listing title as focus keyword’ is closed to new replies.