Issue with Rank Math Schema on Sub-directory Website

#723888
  • Resolved Anonymous
    Rank Math free

    Hello Rank Math Support Team,

    I hope this message finds you well. I am writing to report an issue with the Rank Math plugin’s schema module on my WordPress websites.

    I have two WordPress websites installed on my main domain. The main website is accessible at http://www.mywebsite.com, and the second website is installed in a sub-directory, accessible at http://www.mywebsite.com/shop/. Both websites have the Rank Math plugin installed and activated.

    The problem I am facing is with the schema on the second website (www.mywebsite.com/shop/). The schema is currently generating the sub-directory URL (www.mywebsite.com/shop/) instead of the main domain URL (www.mywebsite.com) in the @id and URL fields. This has the potential to confuse bots, as both websites should ideally have URLs from the main domain.

    I am looking for a solution to change the sub-directory URL to the main domain URL in the @id and URL fields of the schema for the second website. I believe this might be achievable through PHP snippets.

    Could you please provide guidance on how to address this issue? If there are any PHP snippets available to replace the sub-directory URL with the main domain URL in the schema, it would be greatly appreciated.

    Thank you for your assistance in advance. I look forward to your prompt response.

    Best regards

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

    We apologize for the inconvenience you’re experiencing with the Rank Math plugin’s schema module on your sub-directory website. We understand the importance of having the correct URLs in the schema for both websites.

    To address this issue, you can use the following PHP snippet to replace the sub-directory URL with the main domain URL in the schema:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
        if ( is_singular() ) {
            $data['@id'] = str_replace( 'www.mywebsite.com/shop/', 'www.mywebsite.com/', $data['@id'] );
            $data['url'] = str_replace( 'www.mywebsite.com/shop/', 'www.mywebsite.com/', $data['url'] );
        }
        return $data;
    }, 10, 2 );

    You can add this PHP snippet to your theme’s functions.php file or use a custom plugin like Code Snippets to add the code without modifying your theme files directly.

    If you encounter any issues or have further questions, please feel free to reach out to us. We’re here to help!

    Best regards

    Sources:
    Resolving Rank Math Schema Markup Related Issues
    Product Schema Type » Rank Math
    Why You Shouldn’t Duplicate Posts/Pages » Rank Math
    How to Customize Schema Markup for WooCommerce Products » Rank Math
    Using Review Schema Type to Earn Star Ratings » Rank Math

    Anonymous
    Rank Math free

    Hello,

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

    Thank you.

    Hello,

    Thank you for contacting support.

    Those are 2 different WordPress installations, or at least are considered that in the scope of our plugin so the results you see are the expected.

    Our plugin will use the full path to the website, including any sub-domains or paths, to add the IDs to the Schema markup and those cannot be changed.

    Also, since the IDs are only used for associating the different types on the website and preventing duplication of code, it won’t cause any confusion to search engines.

    Don’t hesitate to get in touch if you have any other questions.

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

The ticket ‘Issue with Rank Math Schema on Sub-directory Website’ is closed to new replies.