Skip to content

A simple Google News sitemap is generated on-the-fly for articles that were published in the last two days. Output is saved in cache or as a transient for fast reading and displaying on the front end.

License

Notifications You must be signed in to change notification settings

10up/simple-google-news-sitemap

Simple Google News Sitemap

A simple Google News sitemap is generated on-the-fly for articles that were published in the last two days. Output is saved in cache or as a transient for fast reading and displaying on the front end.

Support Level Release Version WordPress tested up to version License Dependency Review Linting Test

Overview

  • By default, the plugin supports all post types (inc. custom ones). To filter out supported post types, the simple_google_news_sitemap_post_types hook can be used. The example is shown down below.

  • Cached sitemap data is set to expire after 2 days. Also, the data gets purged whenever a new post is published so that it can be included in the sitemap instantly.

  • No sitemap file is stored on disk. Data is served either from the cache or from the DB if caching is not enabled.

  • The plugin also pings the Google service whenever a new post is published. This behaviour can be toggled using the simple_google_news_sitemap_ping filter hook.

  • Utilise the simple_google_news_sitemap_start and simple_google_news_sitemap_end hooks to add data to the beginning and end of the sitemap, respectively.

  • Once the sitemap is generated, add it to the Google Search Console.

Requirements

Usage

  1. Install the plugin. You can upload and install the archived (zip) plugin via the WordPress dashboard (Plugins > Add New -> Upload Plugin) or manually inside of the wp-content/plugins directory, and activate on the Plugins dashboard.
  2. To generate the sitemap, simply visit <YOUR_BLOG_URL>/news-sitemap.xml.
  3. The sitemap will be stored in cache for faster access with an expiry set to 2 days.

Hook Usage

Example (for filtering supported post types):

add_filter( 'simple_google_news_sitemap_post_types', 'filter_post_types' );

function filter_post_types( array $post_types ) {
    // Return the filtered post types
    return $post_types;
}

Troubleshooting

If <YOUR_BLOG_URL>/news-sitemap.xml results in a 404, try saving permalinks and check the sitemap again.

Developers

Local Requirements

Initialise a wp-local-docker instance and inside the wp-content/plugins folder, run the following steps:

git clone git@gitlab.10up.com:10up-internal/simple-google-news-sitemap.git
cd simple-google-news-sitemap
composer install

Once done, go to the plugins page and activate the plugin.

If using Windows, it is recommended to use WSL2 as mentioned here.

Unit Tests

All commands listed below should be run from the root of the plugin folder in your local environment, using 10updocker v2.

10updocker shell
cd wp-content/plugins/simple-google-news-sitemap
composer setup-tests:local

Once the above steps are completed, run composer test for running the unit tests.

Support Level

Beta: This project is quite new and we're not sure what our ongoing support level for this will be. Bug reports, feature requests, questions, and pull requests are welcome. If you like this project please let us know, but be cautious using this in a Production environment!

Changelog

A complete listing of all notable changes to Simple Google News Sitemap are documented in CHANGELOG.md.

Contributing

Please read CODE_OF_CONDUCT.md for details on our code of conduct, CONTRIBUTING.md for details on the process for submitting pull requests to us, and CREDITS.md for a list of maintainers, contributors, and libraries used in this repository.

Like what you see?

About

A simple Google News sitemap is generated on-the-fly for articles that were published in the last two days. Output is saved in cache or as a transient for fast reading and displaying on the front end.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks