Create a Google News sitemap with Ghost
Tags: ghost, handlebars
Published: 2022-10-25 21:17:29

---
title: Create a Google News sitemap with Ghost
published: true
date: 2022-10-25 20:38:37 UTC
tags: Ghost, Handlebars
canonical_url: https://ghost.org/tutorials/create-a-google-news-sitemap/
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2aydt0njwi8yzds2dyt.png
description: Reach new audiences by having your content show up in Google News. Readers get the benefit of discovering your content in a single hub and the ability to share and bookmark articles easily. Learn everything you need to know about adding your Ghost site to Google News in this tutorial.
---

Add your content to Google News by adding a [Google News sitemap](https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap) to your Ghost site. The sitemap lets Google News know all the important details about your published content.

This tutorial walks you through how to create a Google News sitemap by implementing a new route on your Ghost site and by creating a custom template that is fully optimized for the Google News aggregator.

## Add a new route for your sitemap

To make your sitemap accessible on the web, add a new route using Ghost's dynamic routing layer.

Download the most up-to-date version of your `routes.yaml` file from Ghost Admin. Go to **Settings** → **Labs** → **Download current routes.yaml**. Open the file in your [code editor](https://dev.to/royalfig/open-a-theme-in-a-code-editor-5fb0-temp-slug-4104622) of choice.

![Create a Google News sitemap](https://ghost.org/tutorials/content/images/2022/10/CleanShot-2022-10-25-at-16.08.17.png)

Add the following route:

```yaml
routes:
  /sitemap/:
    template: sitemap
    content_type: text/xml
```

This entry tells Ghost to create a route at `yoursite.com/sitemap/`, and on that route, to serve the `sitemap` template file and send an XML response (which is what Google News expects).

Your `routes.yaml` file should now look like the file below, plus any other changes you may have made to it.

```yaml
routes:
  /sitemap/:
    template: sitemap
    content_type: text/xml

collections:
  /:
    permalink: /{slug}/
    template: index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/
```

Save the file and upload it to Ghost Admin ( **Settings** → **Labs** → **Upload routes YAML** ).

## Create a template for the Google News sitemap

The next step is to create a Handlebars template in your theme. This requires a little bit of coding, but the example in this tutorial provides a fully functional starting point.

Create a new file in the root of your theme called `sitemap.hbs`.

### Add your posts

The code below tells Ghost to fetch your latest 1,000 posts and format the information for Google News. The template follows [the specifications for a Google News sitemap](https://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd) like including the title and publication date as well as indicating if the content is for members only.

```handlebars
<?xml version="1.0" encoding="UTF-8"?>
  <urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
  >
    {{#get "posts" limit="1000" include="tags"}}
      {{#foreach posts}}
        <url>
          <loc>{{url absolute="true"}}</loc>
          <news:news>
            <news:publication>
              <news:name>{{@site.title}}</news:name>
              <news:language>{{@site.locale}}</news:language>
            </news:publication>
            {{#has visibility="members"}}
            <news:access>Registration</news:access>
            {{/has}}
            {{#has visibility="paid"}}
            <news:access>Subscription</news:access>
            {{/has}}
            <news:publication_date>{{date published_at format="YYYY-MM-DDTHH:mm:ssZ"}}</news:publication_date>
            <news:title>{{title}}</news:title>
            <news:keywords>{{tags limit="5" autolink="false"}}</news:keywords>
          </news:news>
        </url>
      {{/foreach}}
    {{/get}}
  </urlset>
```

Copy and paste this code to the `sitemap.hbs` file or customize it to suit your needs. With customization, be aware that Google is stringent about attributes and formatting, so be sure [to include all required fields](https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap#news-specific-tag-definitions).

## Update your theme

Save the new template, zip up your theme, and [upload it to your Ghost site](https://dev.to/royalfig/download-and-upload-a-theme-1f2b-temp-slug-9378121). Check to see if your Google News sitemap is active by visiting `yoursite.com/sitemap/`. (We added a sitemap to this Tutorials site as an example: [https://ghost.org/tutorials/sitemap/](https://ghost.org/tutorials/sitemap/).)

![Create a Google News sitemap](https://ghost.org/tutorials/content/images/2022/10/google-news.png)

## Submit your Google News sitemap

Google Search Console is essential for monitoring your search performance in Google. [See our guide on integrating it with Ghost](https://ghost.org/integrations/google-search-console/). It's also the best way to let Google know about your new Google News sitemap.

In Google Search Console, go to Sitemaps and add your new URL to the **Add a new sitemap** box. Click **Submit**. The sitemap should be fetched immediately, but occasionally it can take some time for Google to crawl the URLs listed in it. A successful status indicates that Google has indexed all of your links submitted to Google News. That means your content is available to show up on Google News 📰

## Summary

In this tutorial, you used Ghost's routing system and theme layer to create a custom Google News sitemap 🙌

Creating the sitemap helps your content show up in Google News, but Google also provides several other options for customization, monetization, and improved placement. See [Google's guide](https://support.google.com/news/publisher-center/answer/9607025?hl=en) to learn more.

Having trouble with this tutorial or seeing great success with your new Google News sitemap? Come share your experience in the [official Ghost Forum](https://forum.ghost.org/), where developers, publishers, and content creators come together to discuss all things Ghost.