• If there aren’t any posts flagged for the news sitemap when Google scans it then it returns this error for the sitemap_index.xml:

    Missing XML tag. This required tag is missing. Please add it and resubmit.

    Which is annoying, but not breaking anything. To work around this I added this code to the constructor in xml-news-sitemap-class.xml to skip including the news-sitemap.xml in the sitemap_index.xml when there’s no content in it.

    /**
      * Class constructor
      */
    public function __construct() {
      global $wpdb;
    
      // Always create the sitemap (even when empty) so we don't have 404 messages for it...
      add_action( 'init', array( $this, 'init' ), 10 );
      add_action( 'wpseo_head', array( $this, 'head' ) );
    
      // ...but only add the news sitemap to the index when we have available items for it
      $items = $wpdb->get_results( "SELECT ID FROM $wpdb->posts JOIN $wpdb->postmeta ON ID = post_id
            WHERE post_status='publish'
              AND (DATEDIFF(CURDATE(), post_date_gmt)<=2)
              AND meta_key = '_yoast_wpseo_newssitemap-include'
              AND meta_value = 'on'
              LIMIT 0, 10" );
    
      if ( !empty( $items ) ) {
         add_filter( 'wpseo_sitemap_index', array( $this, 'add_to_index' ) );
      }
    }

    https://www.ads-software.com/extend/plugins/wordpress-seo-news/

  • The topic ‘News sitemap gives an error in Google if no posts are chosen’ is closed to new replies.