Salta la navigazione

Open

Reported for: WPML SEO 2.1.0

Topic Tags: Compatibility

Overview of the issue

The rank_math_html_sitemap shortcode provided by the Rank Math SEO plugin is displaying an HTML sitemap that includes pages from all languages, instead of displaying content only in the current language.

Workaround

Please, make sure of having a full backup of your site before proceeding.

  • Open …/wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/html-sitemap/class-posts.php file.
  • Look for line 88.
  • Change:
    		$sql       = "
    			SELECT l.ID, post_title, post_name, post_parent, post_date, post_type, l.post_modified
    			FROM (
    				SELECT DISTINCT p.ID, p.post_modified FROM {$wpdb->posts} as p
    				LEFT JOIN {$wpdb->postmeta} AS pm ON ( p.ID = pm.post_id AND pm.meta_key = 'rank_math_robots' )
    				WHERE (
    					( pm.meta_key = 'rank_math_robots' AND pm.meta_value NOT LIKE '%noindex%' ) OR
    					pm.post_id IS NULL
    				)
    				AND p.post_type IN ( '" . $post_type . "' ) AND p.post_status IN ( '" . join( "', '", esc_sql( $statuses ) ) . "' )
    				ORDER BY p.post_modified DESC
    			)
    			o JOIN {$wpdb->posts} l ON l.ID = o.ID " . $get_child . " ORDER BY " . $sort['field'] . " " . $sort['order']; // phpcs:ignore
    		return $wpdb->get_results( $wpdb->prepare( $sql ) ); // phpcs:ignore
    
  • For:
    		$current_language = apply_filters( 'wpml_current_language', NULL );				
    		$sql = "
    		SELECT l.ID, post_title, post_name, post_parent, post_date, post_type, l.post_modified
    		FROM (
    			SELECT DISTINCT p.ID, p.post_modified FROM {$wpdb->posts} as p
    			LEFT JOIN {$wpdb->postmeta} AS pm ON ( p.ID = pm.post_id AND pm.meta_key = 'rank_math_robots' )
    			INNER JOIN {$wpdb->prefix}icl_translations AS icl ON ( p.ID = icl.element_id AND icl.language_code = %s AND icl.element_type LIKE 'post_%' )
    			WHERE (
    				( pm.meta_key = 'rank_math_robots' AND pm.meta_value NOT LIKE '%noindex%' ) OR
    				pm.post_id IS NULL
    			)
    			AND p.post_type IN ( %s ) AND p.post_status IN ( '" . join( "', '", esc_sql( $statuses ) ) . "' )
    			ORDER BY p.post_modified DESC
    		) o
    		JOIN {$wpdb->posts} l ON l.ID = o.ID " . $get_child . " ORDER BY " . $sort['field'] . " " . $sort['order']; // phpcs:ignore
    		$sql = $wpdb->prepare($sql, $current_language, $post_type);
    		return $wpdb->get_results( $sql ); // phpcs:ignore
    

Keep in mind that may need to reset your sitemaps. You can do that going to Rank Math SEO > Sitemaps settings, modifying a setting and changing it again.

2 risposte a “Rank Math SEO - rank_math_html_sitemap shortcode lists HTML sitemap in all languages”

    • Hi,

      Thanks for reaching out! It sounds like the issue you’re encountering is related to your site’s robots.txt file, which can indeed prevent Google from crawling your site.
      Here are a few common causes to check:
      – The “Discourage search engines from indexing this site” setting in Settings > Reading in your WordPress dashboard.
      – A similar setting in your SEO plugin (assuming you’re using a plugin like Rank Math SEO).
      – Manually added rules in the robots.txt file that may be blocking crawlers.

      If you’ve reviewed these and the issue persists, feel free to start a live chat with our support team—we’ll be happy to take a closer look!

Lasciare una risposta

Ti preghiamo di rimanere in tema e di essere rispettoso nei confronti degli altri. Se hai bisogno di aiuto per questioni non correlate a questo post, utilizza il nostro Forum di supporto per avviare una chat o inviare un ticket.

Potete usare questi tag:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>