Luke a Pro

Luke Sun

Developer & Marketer

SEO: Sitemap

Published: Tue Dec 27 2022 , 5 minutes reading.

A sitemap is a file that lists all the pages of a website and its content, used to inform search engines about the organization and structure of the site for better indexing and ranking.

To make a sitemap, you can:

Manually create a file in XML format and list all the pages of your website. Use online sitemap generators that automatically create a sitemap based on your website’s structure. Use sitemap-generating plugins or tools if your website is built on a content management system (CMS) such as WordPress. Once created, you can submit the sitemap to search engines using their webmaster tools or by adding it to your robots.txt file.

Does every website need a sitemap?

Not all websites need a sitemap, but it can be beneficial for many websites to have one. Sitemaps are useful for search engines because they provide a way for search engines to quickly and easily discover the pages on a site, and understand the structure and hierarchy of the site. Sitemaps can also help search engines index your site more efficiently and effectively, especially if your site has a complex structure or if it is difficult for search engines to discover all of the pages on your site through normal crawling.

If your website has a small number of pages and is well-structured, then a sitemap may not be necessary. However, if your site has a large number of pages or if it is difficult for search engines to discover all of the pages on your site, then a sitemap can be very helpful in ensuring that your site is fully indexed by search engines.

What does a sitemap file look like?

pass this section if you don’t interest in its implementation

A sitemap file is typically written in XML format, and it lists all the pages of a website along with additional information such as the date the page was last modified, the frequency with which the page is likely to change, and the relative importance of the page compared to other pages on the site.

Here is an example of a basic sitemap file:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://soft.pw/blog/</loc>
    <lastmod>2023-01-28</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://soft.pw/blog/read/020-what-is-full-stack-mean/</loc>
    <lastmod>2023-01-28</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.5</priority>
  </url>
  <!-- additional URLs -->
</urlset>

In this example, each <url> element represents a single page on the site, and the <loc> element specifies the URL of the page. The <lastmod> element is the date the page was last modified, the <changefreq> element is the frequency with which the page is likely to change, and the <priority> element is the relative importance of the page compared to other pages on the site.

Where to submit my sitemap file?

The sitemap file can be submitted to search engines through their webmaster tools:

  • Google Search Console
  • Bing Webmaster Tools
  • Yandex Webmaster

To submit the sitemap, you will need to create an account with each search engine and verify your website ownership. Once verified, you can access the webmaster tools and submit the sitemap file by adding the URL of the sitemap to the sitemap section of the tools.

Can I submit sitemap file via API?

Yes, you can submit a sitemap file to some search engines via APIs. For example, Google Search Console has an API for submitting and managing sitemaps, which allows you to automate the process of submitting and updating sitemaps. To use the API, you will need to have a Google account and access to the Google Cloud Console. Bing Webmaster Tools also provides an API for submitting sitemaps. Yandex Webmaster doesn’t provide an API for sitemap submission, it has to be done through the webmaster tools interface.

Google

import requests

url = 'https://www.google.com/webmasters/tools/ping?sitemap='
sitemap_url = 'http://www.soft.pw/sitemap-index.xml'

response = requests.get(url + sitemap_url)

if response.status_code == 200:
  print('Sitemap submitted successfully!')
else:
  print('Failed to submit sitemap.')

Bing

import requests

sitemap_url = "http://www.soft.pw/sitemap-index.xml"
submit_url = f"http://www.bing.com/ping?sitemap={sitemap_url}"

response = requests.get(submit_url)

if response.status_code == 200:
  print("Sitemap submitted successfully to Bing Webmaster Tools")
else:
  print("Failed to submit sitemap to Bing Webmaster Tools")