Viewing 6 replies - 1 through 6 (of 6 total)
  • This might not be your preferred solution, but we ran into this with static site where we have main site, ecom site, news site, and blog — 3 diff WP installs. What we did was setup the robots.txt to point at all four sitemaps, 3 by yoast, one by another plugin for our custom CMS.

    Submitted all four sitemaps to Google, Bing, Yandex. Works.

    Thread Starter Mani Karthik

    (@emkaykay)

    Got it. I’m aware of the Robots.txt option, but also making sure that if there is a possibility to include it in the index, then try that out.

    Reason – We’ve submitted the other sitemaps via Search Console, but the number of pages indexed v/s submitted is showing a difference. So, the assumption is that this might be happening because the sitemap is not included in the index (therefore, less weightage).

    Will add the sitemap to Robots.txt but would love to see an option where the Sitemap Index can be edited.

    Thanks

    Plugin Support amboutwe

    (@amboutwe)

    Have you tried the information found here?

    If it did not work, please elaborate on what didn’t work.

    It worked, but how do I keep the <lastmod> entry recent instead of hardcoded to the past?

    function add_sitemap_custom_items(){
    $sitemap_custom_items = ‘<sitemap>
    <loc>https://www.naturallifeenergy.com/blogs/post-sitemap.xml</loc&gt;
    <lastmod>2012-12-18T23:12:27+00:00</lastmod>
    </sitemap>
    <sitemap>
    <loc>https://www.naturallifeenergy.com/blogs/post-sitemap.xml</loc&gt;
    <lastmod>2012-12-18T23:12:27+00:00</lastmod>
    </sitemap>’;
    return $sitemap_custom_items;
    }
    add_filter( ‘wpseo_sitemap_index’, ‘add_sitemap_custom_items’ );

    Better late than never, place the following code into your functions.php file (or place in a separate plugin). What this does is get a list of all of the sub-sites, and for each sub-site, get the most recently modified content date (can be post, or page, or whatever), converts it to the proper format, and uses that for the lastmod node of each subsite xml listing.

    Tested on WordPress 4.7

    // add subsite sitemaps to sitemap.xml
    function add_sitemap_custom_items() {
    
      // only add the xml of the subsites to the main site
      if (get_current_blog_id() === 1) {
    
        // set blank content variable
        $sitemap_custom_items = '';
    
        // set arguments for getting the most recent page (or post, or attachment or post type)
        $recent_args = array(
          'numberposts' => 1,
          'post_type' => 'page', // this can be posts OR attachment, OR whatever post type you want.
          'post_status' => 'publish',
          'suppress_filters' => true
        );
    
        // get the subsites as an object
        $subsites = get_sites();
        
        // loop through the subsites 
        foreach( $subsites as $subsite ) {
    
          // store subsite details
          $subsite_id = get_object_vars($subsite)['blog_id'];
          $subsite_domain = get_object_vars($subsite)['domain'];
          $subsite_slug = get_object_vars($subsite)['path'];
    
          // we don't need to worry about the main site
          if ($subsite_id != 1) {
    
            // switch to the site currently in the foreach loop
            switch_to_blog($subsite_id);
    
              // get the most recent page (as based on the arguments above)
              $subsite_pages = wp_get_recent_posts($recent_args);
    
              // create a loop to get the details of the first post passed
              foreach ($subsite_pages as $subsite_page) : setup_postdata($subsite_page);
    
                // get the latest modified timestamp and format it to ISO 8601 date format (aka 'c' in php5)
                $latest_mod_date = date('c', strtotime($subsite_page['post_modified']));
    
              endforeach;
    
              // clear query
              wp_reset_postdata();
    
            // switch back to the main site
            restore_current_blog();
    
            // concatenate this subsite sitemap xml with the domain, slug and proper latest modified content date for that site
            $sitemap_custom_items .= "<sitemap><loc>https://".$subsite_domain."".$subsite_slug."page-sitemap.xml</loc><lastmod>".$latest_mod_date."</lastmod></sitemap>\n";
    
          }
    
        }
    
        // output list of sitemap.xml's for each site
        return $sitemap_custom_items;
    
      }
    
    }
    add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
    • This reply was modified 7 years, 11 months ago by mkormendy.
    • This reply was modified 7 years, 11 months ago by mkormendy.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding an external sitemep to the sitemap index’ is closed to new replies.