Eleventy site.url is missing

Eleventy site.url is missing

2 min read
11ty websites

By default, 11ty knows nothing about the root domain of your website. A number of scenarios (e.g. setting up sitemap.xml) require the full path of your site, while many 11ty tutorials make the assumption that you've set up your 11ty system to do so.

If site.url is undefined it's because it needs to be defined in your Eleventy configuration or data files. In Eleventy, global data like this is typically defined in one of two ways:

  1. In a global data file (recommended): Create a new file _data/site.json or src/_data/site.json (depending on your project structure):
{
  "url": "https://yourdomain.com"
}
  1. Or in your Eleventy config file (eleventy.config.cjs or similar):
module.exports = function(eleventyConfig) {
  // ... other config ...

  eleventyConfig.addGlobalData("site", {
    url: "https://yourdomain.com"
  });

  // ... other config ...
};

After adding either of these, site.url will be available in your templates. Happy building!

Share: X