View Categories

How to add sitemap for SEO and Indexing

3 min read

Sitemaps are extremely important for the indexing of your website. It lets search engines know every time a new listing is added to your website. Sitemaps are also helpful in explaining the structure of your website to the search engine and AI search agents. In this article, I will share how you can add a sitemap to your website for the listings.

Depending on whether you are using Wix Studio or Wix Editor, the implementation steps are slightly different.

How to add Real Estate Listings Sitemap #

Follow these steps to add the sitemap to your Wix website for the real estate listings app.

Step 1 – Turn on the dev mode #

Turn on the developer mode in your Wix Editor or Wix Studio website. The following video shows how to turn on the developer/coding mode in both Wix Studio and Wix Editor. Use the relevant method according to your editor type.

Step 1 – Turn on the dev mode

Step 2 – Add a Router Page with the name “real-estate-listing” #

After the Dev Mode is turned on, add a Router page to your website. We will only use it to add the sitemap. The name of the router page will be “Real Estate Listing”. This is case sensitive; please make sure that the router name is “real estate listing” only. The following video shows how to add a router page in Wix Studio and Wix Editor, respectively. Use a relevant method as per your Editor type.

Step 2 – Add a Router Page with the name real-estate-listing

Step 3 – Add the Code for Generating Sitemap in the routers.js file #

The final step is to add the simple code given below to the routers.js file in your website backend.

import { ok, notFound, WixRouterSitemapEntry } from "wix-router";
import wixData from "wix-data";

const COLLECTION_ID = "@v-blog/real-estate-listing/RealEstateListing";

export async function real_estate_listings_Router(request) {
  const slug = request.path[0];
  const results = await wixData.query(COLLECTION_ID).eq("slug", slug).find();

  if (results.items.length > 0) {
    const data = results.items[0];

    const seoData = {
      title: data.title,
      description: "This is a description of " + data.title + " page",
      noIndex: false,
      metaTags: [
        {
          property: "og:title",
          content: data.title,
        },
      ],
    };

    return ok("real-estate-listing-page", data, seoData);
  }

  return notFound();
}

export async function real_estate_listing_SiteMap(sitemapRequest) {
  const results = await wixData.query(COLLECTION_ID).find();

  const siteMapEntries = results.items.map((item) => {
    const entry = new WixRouterSitemapEntry(item.slug);
    entry.pageName = "real-estate-listing-item";
    entry.url = "/real-estate-listing-item/" + item.slug;
    entry.title = item.title;
    return entry;
  });

  return siteMapEntries;
}

export function real_estate_listing_Router(request) {}

The following video shows how to add the code in the backend. After adding the code in the backend, publish the website and disable dev mode (if not needed).

Step 3 – Add the Code for Generating Sitemap in the routers.js file

Step 4 – Validate the sitemap #

Your sitemap is now added to the website. You can access it from the URL “yourdomain.com/dynamic-real-estate-listing-sitemap.xml” replace the domain in the link. Here is an example of what your sitemap will look like.

Leave a Reply

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