WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO News
News sitemap gives an error in Google if no posts are chosen (1 post)

  1. Katherine Semel-Munson
    Member
    Posted 1 year ago #

    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' ) );
      }
    }

    http://wordpress.org/extend/plugins/wordpress-seo-news/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Katherine Semel-Munson
  • This topic is not resolved
  • WordPress version: 3.4.2