Issue in links indexed in sitemap

#691093
  • Resolved Mohammed Adel
    Rank Math free

    Hello,
    I have an issue with Post & Categories links indexed in Site Map in one of my websites.

    When I activate the WPML plugin first time I have choosed English as the main language and Arabic second. Then I have changed later the arabic to be the main and not used English again.

    The issue is that Arabic Posts and Categories Links still appear like that: https://website.com/ar
    ” /ar ” not exist now and this leads to make pages appears 404 in google and website not indexed

    I need your kind support to fix that

    Thanks,
    Mohamed

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

    We apologize for the inconvenience you’re experiencing with the links indexed in the sitemap. It seems that the issue is related to the incorrect entries for the secondary homepage in the sitemap.

    To resolve this issue, you can add a piece of code to your theme’s functions.php file. Here’s the code you need to add:

    if ( 'page' === get_option( 'show_on_front' ) ) {
        add_filter( 'rank_math/sitemap/entry', 'compsupp_5514_filter_sitemap_home_page_entry', 10, 3 );
    }
    function compsupp_5514_filter_sitemap_home_page_entry( $url, $type, $post ) {
        global $sitepress;
        static $wpml_home_urls = null;
        static $frontpage_translations = null;
        static $default_frontpage_id = null;
        if ( ! $wpml_home_urls ) {
            $active_languages = $sitepress->get_active_languages();
            $wpml_home_urls   = [];
            foreach ( $active_languages as $code => $language ) {
                $wpml_home_urls[ $code ] = $sitepress->language_url( $code );
            }
            $default_frontpage_id   = get_option( 'page_on_front' );
            $frontpage_trid         = $sitepress->get_element_trid( $default_frontpage_id, 'post_page' );
            $frontpage_translations = array_map( WPMLFPObj::prop( 'element_id' ), $sitepress->get_element_translations( $frontpage_trid, 'post_page' ) );
        }
        if ( in_array( $post->ID, $frontpage_translations ) && $post->ID !== $default_frontpage_id  ) {
            $language_code = array_search( $post->ID, $frontpage_translations );
            $url['loc']    = $wpml_home_urls[ $language_code ];
        }
        return $url;
    }

    Please ensure to take a backup of your website’s files and database before making any changes to the code.

    After adding this code, the issue with the incorrect entries for the secondary homepage in the sitemap should be resolved.

    If you need further assistance or have any other questions, please feel free to ask.

    Thank you for reaching out to us!

    Sources:
    Multilingual SEO with Rank Math SEO & WPML » Rank Math
    Rank Math Sitemap Issues and Their Fixes » Rank Math

    Hello,

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

    Thank you.

    Thanks for your reply
    The issue still exist in:
    post-sitemap.xml
    category-sitemap.xml

    Links still have the slug ” /ar/ “

    Hello,

    Thank you for your patience.

    For initial troubleshooting, please follow the steps to flush the sitemap cache:

    1. Flush the Sitemap cache by following this video screencast:
    https://i.rankmath.com/pipRDp

    2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
    https://rankmath.com/kb/exclude-sitemaps-from-caching/

    3. Disable the transient cache for the sitemap by applying this filter. This will make sure that your XML sitemap always reflects the latest changes on your site:

    /** 
     * Filter if XML sitemap transient cache is enabled.
     *
     * @param boolean $unsigned Enable cache or not, defaults to true
     */
    add_filter( 'rank_math/sitemap/enable_caching', '__return_false');

    If you’re not sure how to add this code, you can follow this guide:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how this goes.

    Thanks for your support, links are fixed now

    Hello,

    Awesome!!!

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘Issue in links indexed in sitemap’ is closed to new replies.