Google News Sitemap XML for WordPress: Beginner’s Guide

Last Updated on June 19, 2025
How to Create a Google News Sitemap XML for WordPress

If you’re running a WordPress site and want your latest articles to be picked up quickly by Google News, a dedicated news-sitemap.xml is a must-have. Unlike regular sitemaps, a News sitemap only contains articles published in the last 48 hours and includes special <news:…> metadata that Google requires .

Many free plugins either don’t support custom post types or add unnecessary overhead, and top SEO suites like Yoast or Rank Math lock this behind premium tiers.

This practical, no-plugin solution shows you how to generate a perfect news sitemap, including only posts from the last 2 days (including custom post types), auto-removing old URLs as they age out, and fully complying with Google’s requirements.

Let’s dive in!

What Is a News Sitemap and Why You Need It

A News Sitemap is a specialized XML file that lists only your recent news articles (published within the last 48 hours) with specific <news:…> tags. Google News crawls this file frequently to discover breaking stories. Without it, you rely on your standard sitemap and occasional crawls, which can delay indexing.

Benefits:

  • Faster Discovery: Google News fetches it more often.
  • Greater Visibility: Ensures your freshest articles surface in News search.
  • Control: You decide exactly which post types and articles appear.

Key Google requirements:

  • Include only news articles from the last 2 days
  • Exclude “pages” and other non-news content
  • Update automatically as new articles are published or old ones age out

Key Differences from a Standard Sitemap

AspectStandard SitemapNews Sitemap
Content WindowAll URLsOnly articles from the past 2 days
Namespacexmlns="http://www.sitemaps.org/schemas/sitemap/0.9"Includes xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
Required News Tagsn/a<news:publication>, <news:publication_date>, <news:title>, etc.
Max URLs50,000 per file1,000 <news:news> entries per file (max)

Fastest, Easiest Solution: The Standalone PHP Sitemap

Many WordPress plugins claim to generate news sitemaps, but they often run into problems:

  • 404 errors on /news-sitemap.xml
  • Pages showing up in the sitemap
  • Most of the top SEO plugins offer this feature in paid plan.
  • Custom post types missing or broken formatting

This guide solves those issues 100%.

Prerequisites

  • A self-hosted WordPress install
  • Access to your site’s filesystem (FTP, SSH, or File Manager, or using Theme Editor)
  • Basic comfort editing PHP files
  • (If using a custom post type) Know its slug (e.g. blog, news, articles)

Step-by-Step: Custom News Sitemap at

Step 1: Copy the Code

Add the following code to your theme’s functions.php file:

  1. Go to your WordPress dashboard.
  2. Go to Appearance → Theme File Editor.
  3. On the right, click functions.php (often called “Theme Functions”).
  4. Paste this code at the very end of the file.
// Register "news-google.xml" as a custom endpoint
add_filter('query_vars', function($vars) {
    $vars[] = 'news_google_sitemap';
    return $vars;
});

add_action('init', function() {
    add_rewrite_rule('^news-google\.xml$', 'index.php?news_google_sitemap=1', 'top');
});

// Output the XML when someone visits /news-google.xml
add_action('template_redirect', function() {
    if (get_query_var('news_google_sitemap')) {
        header('Content-Type: application/xml; charset=UTF-8');

        // Your news sitemap logic (last 2 days, all post types except pages)
        $post_types = get_post_types(['public' => true], 'names');
        unset($post_types['page']); // Exclude pages
        $post_types = array_unique(array_merge(['post'], $post_types));
        $now = current_time('timestamp');
        $two_days_ago = $now - 2 * DAY_IN_SECONDS;

        $args = [
            'post_type'      => $post_types,
            'post_status'    => 'publish',
            'posts_per_page' => 1000,
            'date_query'     => [[
                'after'     => date('Y-m-d H:i:s', $two_days_ago),
                'before'    => date('Y-m-d H:i:s', $now),
                'inclusive' => true,
            ]],
            'orderby'        => 'date',
            'order'          => 'DESC',
            'fields'         => 'ids'
        ];

        $posts = get_posts($args);
        $publication_name = get_bloginfo('name');
        $publication_lang = substr(get_bloginfo('language'), 0, 2);

        echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
        echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ';
        echo 'xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">' . "\n";

        foreach ($posts as $post_id) {
            $post = get_post($post_id);
            echo "  <url>\n";
            echo '    <loc>' . esc_url(get_permalink($post)) . "</loc>\n";
            echo "    <news:news>\n";
            echo "      <news:publication>\n";
            echo '        <news:name>' . esc_html($publication_name) . "</news:name>\n";
            echo '        <news:language>' . esc_html($publication_lang) . "</news:language>\n";
            echo "      </news:publication>\n";
            echo '      <news:publication_date>' . esc_html(get_the_date('c', $post)) . "</news:publication_date>\n";
            echo '      <news:title>' . esc_html(get_the_title($post)) . "</news:title>\n";
            echo "    </news:news>\n";
            echo "  </url>\n";
        }
        echo "</urlset>\n";
        exit;
    }
});

Step 2: Flush Permalinks

After you save the file, you need to tell WordPress about the new URL:

  1. Go to Settings → Permalinks in your WordPress dashboard.
  2. Scroll down and click Save Changes (you don’t need to actually change anything).
    • This step is very important!

Step 3: Test Your New News Sitemap

In your browser, go to:
https://yourdomain.com/news-google.xml
(replace yourdomain.com with your actual site)

  • You should see an XML file that lists your news articles from the last 2 days.

Step 4: Submit to Google (if you want)

You can now submit this sitemap URL (https://yourdomain.com/news-google.xml) to Google News Publisher Center or Google Search Console.

FAQs

What if I see a 404 error?

Make sure you flushed permalinks (Step 2).
Clear any caching (plugin cache, server cache, Cloudflare, etc.).
Make sure the code is at the end of your active theme’s functions.php.

Does this work with Rank Math & Yoast SEO?

YES! Because the URL is /news-google.xml (not /news-sitemap.xml), Rank Math & Yoast SEO does NOT take over, and your custom sitemap works perfectly.

Can I change the URL?

Yes, just change every mention of news-google in the code to whatever you want (like breaking-news).

Pro Tips & Best Practices

  • 48‑hour window: Stick to Google’s 2-day limit—older URLs won’t be indexed by News.
  • 1,000 URL cap: If you publish >1,000 news posts in 48 hours, split sitemaps (e.g., date-based).
  • Exact Publication Date: Use get_the_date('c') to output YYYY-MM-DDThh:mm:ss+TZ.
  • Language Codes: Use ISO 639-1 (e.g., en, es, zh-cn).
  • Publication Name: Must match the name in your Google News Publisher Center.
  • Avoid caching: Exclude /news-sitemap.xml from page or CDN caches—freshness is key.
  • Submit in Search Console: Add /news-sitemap.xml under Sitemaps; Google News will auto-refresh.
  • Monitor errors: In GSC under Sitemaps, check for parsing or crawl issues.
  • Shard if needed: For very high-volume sites, consider multiple sitemaps by date or category.

Troubleshooting Common Issues

IssuePossible CauseSolution
404 on /news-sitemap.xmlPermalinks not flushed1. Go to Settings→Permalinks, click Save Changes

2. If issues is still there – If you’re on Apache, open the .htaccess in the root of your WordPress install and just above the RewriteCond %{REQUEST_FILENAME} !-f

Insert this

BEGIN News Sitemap
RewriteRule ^news-google.xml$ /index.php?news_google_sitemap=1 [L,QSA]
END News Sitemap

If your host uses Nginx, you need to pass the pretty URL through too. Inside your server { … } block (usually in /etc/nginx/sites-available/…), make sure you have:

location = /news-googlexml {
try_files $uri $uri/ /index.php?news_google_sitemap=1&$args;
}


And that your main block already has:

location / {
try_files $uri $uri/ /index.php?$args;
}


Then reload Nginx:

sudo service nginx reload
Empty sitemapNo posts in last 2 daysPublish a new post or adjust server time
XML parse errorsMalformed XML or missing headersEnsure header() is correct and exit; after XML
CPT entries missingWrong slug or code placementVerify CPT slug, plugin code order, re-flush

That’s it!

  • No conflicts with Rank Math or any other sitemap plugin.
  • No plugin needed.
  • No PHP files in your root directory.

After following the instructions above, you’ll see your news-sitemap.xml file live, as mine is – see the screenshot below.

Google News Sitemap XML for WordPress screenshot

Happy publishing, and may your headlines reach more readers!

Reference:
Build and submit a sitemap
News sitemaps

About the author:
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts