Adding a Sitemap to Your Ghost Site for Google Search Engine Indexing
25-06-2024
25-06-2024
Introduction
In this technical blog post, I will guide you through the process of adding a sitemap to your Ghost site, enabling better indexing and content discovery by the Google search engine. By following these steps, you will utilize Ghost's routing system and theme layer to create a sitemap specifically formatted for Google.
Step 1: Creating a New Route for the Sitemap
Begin by creating a file named "routes.yaml" and add the following code to it:
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 the Ghost Admin area by navigating to Settings -> Labs -> Upload routes YAML.
Step 2: Creating the Sitemap Template
In the root of your Ghost theme, create a file named "sitemap.hbs" and copy the following code into it:
<?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>
This code fetches your latest 1000 posts and formats them for Google News. You can modify the number of posts to suit your needs.
Step 3: Uploading and Activating the Sitemap
Zip your Ghost theme (including the routes.yaml and sitemap.hbs files) and upload it to your Ghost site. Verify that the sitemap is active by visiting the URL "yoursite.com/sitemap".
Step 4: Integrating Google Search Console
If you haven't already integrated Ghost and Google Search Console, you can follow the tutorial available at: https://ghost.org/integrations/google-search-console/?ref=ghost.org
Step 5: Submitting the Sitemap to Google Search Console
After integrating Ghost and Google Search Console, select your website in the console. Go to the "Sitemaps" section and add the sitemap URL to the "Add a new sitemap" box. Google will fetch the sitemap immediately, but indexing may take some time.
Conclusion
Congratulations! You have successfully added a sitemap to your Ghost site for Google search engine indexing. By utilizing Ghost's routing system and theme layer, you have created a sitemap specifically formatted for Google, allowing for improved content discovery and indexing. Enjoy the benefits of increased visibility and search engine optimization for your Ghost site.
References:
https://ghost.org/tutorials/create-a-google-news-sitemap/ https://yoast.com/help/submit-sitemap-search-engines/#google-submit