{"id":2699,"date":"2025-08-17T20:38:47","date_gmt":"2025-08-17T13:38:47","guid":{"rendered":"https:\/\/siammakemoney.com\/?p=2699"},"modified":"2025-08-19T21:26:23","modified_gmt":"2025-08-19T14:26:23","slug":"sitemap-xml","status":"publish","type":"post","link":"https:\/\/siammakemoney.com\/en\/sitemap-xml\/","title":{"rendered":"How to create a sitemap.xml with your own code (Sitemap index file)"},"content":{"rendered":"<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-c8cdb34af6fd810e65dbedd894bbe172\" style=\"color:#336864;font-size:28px\">Create a simple and basic Sitemap Index sitemap.xml<\/h2>\n\n\n\n<p>Creating a sitemap.xml file with Python code to help search engines know our web pages. There is an example for a static website that uses .html and .php files, along with instructions on how to use it and send it to Google &amp; Bing via Search Console or ping URL.<\/p>\n\n\n\n<p>A sitemap is a file that compiles the URLs of important pages on your website, helping search engines understand and navigate your pages more easily, which is good for SEO and increasing traffic. Here&#039;s how to create and submit a sitemap to Google for maximum efficiency.<\/p>\n\n\n<style scoped>\n            .gc-box{margin-bottom:30px;padding:20px;border-left:5px solid transparent;line-height:24px}.gc-box .label-info{background-color:#5bc0de;display:inline-block;margin:0 5px 10px 0;padding:3px 6px;font-size:75%;font-weight:700;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;line-height:14px}.gc-box.green_type{color:#3c763d;background-color:#dff0d8;border-color:#cae6be}.gc-box.blue_type{color:#31708f;background-color:#d9edf7;border-color:#bcdff1}.gc-box.red_type{color:#a94442;background-color:#f2dede;border-color:#e8c4c4}.gc-box.grey_type{background:#ddd;border-color:#ccc;color:#444}.gc-box.info_type{color:#155724;background-color:#d4edda;border-color:#c3e6cb}.gc-box.info_type svg{fill:#30a030}.gc-box.download_type{color:#004085;background-color:#cce5ff;border-color:#b8daff}.gc-box.download_type svg{fill:#3a9aff}.gc-box.update_type{color:#004458;background-color:#d9edf7;border:1px solid #bce8f1}.gc-box.notice_type{color:#856404;background-color:#fff3cd;border-color:#ffeeba}.gc-box.notice_type svg{fill:#f7a000}.gc-box.error_type{color:#721c24;background-color:#f8d7da;border-color:#f5c6cb}.gc-box.error_type svg{fill:#c70000}.gc-box.border_type{border:2px solid #ddd}.gc-box.icon_type{display:flex}.gc-box.icon_type .gc-box-icon{width:28px}.gc-box.icon_type .gc-box-text{flex-grow:1;margin:0 15px}.gc-box-text > *{margin-bottom: 20px;}\n        .gc-box-text > *:last-child{margin-bottom:0}        \n        <\/style><div class=\"gc-box border_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-51055fbf0388df6c69b33d911bf8dd7c\" style=\"color:#1a8079;font-size:30px\">1. Understanding Sitemaps and Sitemap Indexes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sitemap<\/strong>: It is an XML file that tells search engines like Google which pages are on our website.<\/li>\n\n\n\n<li><strong>Sitemap Index<\/strong>: It is an XML file that combines multiple sub-sitemaps, making it easier to manage large websites.<\/li>\n<\/ul>\n\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-4ed54ffd6bbffb7b553baccf8f8027dd\" style=\"color:#1a8079;font-size:33px\">2. Standard structure of <code>sitemap.xml<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code has-layout-color has-primary-background-color has-text-color has-background has-link-color wp-elements-e40b4577af5bec78e62226967e473053\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;urlset xmlns=\"http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9\"&gt;\n   &lt;url&gt;\n      &lt;loc&gt;https:\/\/yourdomain.com\/&lt;\/loc&gt;\n      &lt;lastmod&gt;2025-08-17&lt;\/lastmod&gt;\n      &lt;changefreq&gt;weekly&lt;\/changefreq&gt;\n      &lt;priority&gt;1.0&lt;\/priority&gt;\n   &lt;\/url&gt;\n   &lt;url&gt;\n      &lt;loc&gt;https:\/\/yourdomain.com\/about&lt;\/loc&gt;\n      &lt;lastmod&gt;2025-08-10&lt;\/lastmod&gt;\n      &lt;changefreq&gt;monthly&lt;\/changefreq&gt;\n      &lt;priority&gt;0.8&lt;\/priority&gt;\n   &lt;\/url&gt;\n&lt;\/urlset&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;loc&gt;<\/code> = URL of web page<\/li>\n\n\n\n<li><code>&lt;lastmod&gt;<\/code> = Last updated date (format <code>YYYY-MM-DD<\/code>)<\/li>\n\n\n\n<li><code>&lt;changefreq&gt;<\/code> = Expected update frequency (<code>always, hourly, daily, weekly, monthly, yearly, never<\/code>)<\/li>\n\n\n\n<li><code>&lt;priority&gt;<\/code> = Importance value (0.0 \u2013 1.0)<\/li>\n<\/ul>\n\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-81fe5f9902deff5bc85eca39e6c34165\" style=\"color:#1a8079;font-size:28px\">3. Example Python code for creation <code>sitemap.xml<\/code><\/h2>\n\n\n\n<p>This code will read a list of URLs and write a sitemap.xml file for you.<\/p>\n\n\n\n<pre class=\"wp-block-code has-layout-color has-primary-background-color has-text-color has-background has-link-color wp-elements-9bb92c555b4aef21e53d696222667d1a\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>import datetime\n\n\ndomain = \"https:\/\/yourdomain.com\"\npages = &#91;\n    \"\/\", \n    \"\/about\", \n    \"\/contact\", \n    \"\/products\", \n    \"\/blog\"\n]\n\ntoday = datetime.date.today().isoformat()\n\nsitemap_path = \"sitemap.xml\"\n\nwith open(sitemap_path, \"w\", encoding=\"utf-8\") as f:\n    f.write('&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\\n')\n    f.write('&lt;urlset xmlns=\"http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9\"&gt;\\n')\n\n    for page in pages:\n        f.write(\"  &lt;url&gt;\\n\")\n        f.write(f\"    &lt;loc&gt;{domain}{page}&lt;\/loc&gt;\\n\")\n        f.write(f\"    &lt;lastmod&gt;{today}&lt;\/lastmod&gt;\\n\")\n        f.write(\"    &lt;changefreq&gt;weekly&lt;\/changefreq&gt;\\n\")\n        f.write(\"    &lt;priority&gt;0.8&lt;\/priority&gt;\\n\")\n        f.write(\"  &lt;\/url&gt;\\n\")\n\n    f.write(\"&lt;\/urlset&gt;\\n\")\n\n\nprint(\"Sitemap index created successfully!\")\n\n<\/code><\/pre>\n\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-81126ab25a02d9f88c68df1cc553be65\" style=\"color:#1a8079;font-size:30px\">4. Create a Sitemap for a Static Website<\/h2>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color wp-elements-bbc613cd338dc0905678b7a178f71d37\" style=\"color:#e46618;font-size:25px\">4.1 For (plain .HTML files) static pages<\/h3>\n\n\n\n<p>If your website is <strong>Static website (plain HTML)<\/strong> And there are many pages such as<\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#faf2e5\" data-no-translation=\"\" data-no-auto-translation=\"\"><code><strong><em>\/index.html  \n\/about.html  \n\/contact.html  \n\/blog.html  \n\/products\/product1.html  \n\/products\/product2.html<\/em><\/strong><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Python code sample to create a Sitemap for a Static website<\/h5>\n\n\n\n<pre class=\"wp-block-code has-layout-color has-primary-background-color has-text-color has-background has-link-color wp-elements-74cd5f3769c73228722652c73bcd71b7\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>import os, datetime\n\n\ndomain = \"https:\/\/yourdomain.com\"\nweb_dir = \".\/public_html\"  \ntoday = datetime.date.today().isoformat()\n\nurls = &#91;]\n\n\nfor root, dirs, files in os.walk(web_dir):\n    for file in files:\n        if file.endswith(\".html\"):\n            rel_path = os.path.relpath(os.path.join(root, file), web_dir)\n            url = \"\/\" + rel_path.replace(\"\\\\\", \"\/\")\n            if url.endswith(\"index.html\"):\n                url = url.replace(\"index.html\", \"\") \n            urls.append(url)\n\n\nsitemap_path = os.path.join(web_dir, \"sitemap.xml\")\nwith open(sitemap_path, \"w\", encoding=\"utf-8\") as f:\n    f.write('&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\\n')\n    f.write('&lt;urlset xmlns=\"http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9\"&gt;\\n')\n    for url in urls:\n        f.write(\"  &lt;url&gt;\\n\")\n        f.write(f\"    &lt;loc&gt;{domain}{url}&lt;\/loc&gt;\\n\")\n        f.write(f\"    &lt;lastmod&gt;{today}&lt;\/lastmod&gt;\\n\")\n        f.write(\"    &lt;changefreq&gt;monthly&lt;\/changefreq&gt;\\n\")\n        f.write(\"    &lt;priority&gt;0.5&lt;\/priority&gt;\\n\")\n        f.write(\"  &lt;\/url&gt;\\n\")\n    f.write(\"&lt;\/urlset&gt;\\n\")\n\nprint(\"Sitemap index created successfully!\")<\/code><\/pre>\n\n\n\n<p>This code will scan all .html files in your web folder and automatically write a sitemap.xml.<\/p>\n\n\n<div class=\"gc-box notice_type icon_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><svg x=\"0px\" y=\"0px\" viewbox=\"0 0 486.463 486.463\" > <g> <g> <path d=\"M243.225,333.382c-13.6,0-25,11.4-25,25s11.4,25,25,25c13.1,0,25-11.4,24.4-24.4 C268.225,344.682,256.925,333.382,243.225,333.382z\"\/> <path d=\"M474.625,421.982c15.7-27.1,15.8-59.4,0.2-86.4l-156.6-271.2c-15.5-27.3-43.5-43.5-74.9-43.5s-59.4,16.3-74.9,43.4 l-156.8,271.5c-15.6,27.3-15.5,59.8,0.3,86.9c15.6,26.8,43.5,42.9,74.7,42.9h312.8 C430.725,465.582,458.825,449.282,474.625,421.982z M440.625,402.382c-8.7,15-24.1,23.9-41.3,23.9h-312.8 c-17,0-32.3-8.7-40.8-23.4c-8.6-14.9-8.7-32.7-0.1-47.7l156.8-271.4c8.5-14.9,23.7-23.7,40.9-23.7c17.1,0,32.4,8.9,40.9,23.8 l156.7,271.4C449.325,369.882,449.225,387.482,440.625,402.382z\"\/> <path d=\"M237.025,157.882c-11.9,3.4-19.3,14.2-19.3,27.3c0.6,7.9,1.1,15.9,1.7,23.8c1.7,30.1,3.4,59.6,5.1,89.7 c0.6,10.2,8.5,17.6,18.7,17.6c10.2,0,18.2-7.9,18.7-18.2c0-6.2,0-11.9,0.6-18.2c1.1-19.3,2.3-38.6,3.4-57.9 c0.6-12.5,1.7-25,2.3-37.5c0-4.5-0.6-8.5-2.3-12.5C260.825,160.782,248.925,155.082,237.025,157.882z\"\/> <\/g> <\/g> <\/svg><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h4 class=\"wp-block-heading\">\ud83d\udd39 Usage<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Put this code in your project folder (eg. <code>generate_sitemap.py<\/code>)<\/li>\n\n\n\n<li>Run with <code>python generate_sitemap.py<\/code><\/li>\n\n\n\n<li>You will get the file <code>sitemap.xml<\/code> Located at the root (<code>public_html\/sitemap.xml<\/code>)<\/li>\n\n\n\n<li>Open in browser \u2192 <code>https:\/\/yourdomain.com\/sitemap.xml<\/code><\/li>\n\n\n\n<li>Submit to Google &amp; Bing (use Search Console or ping URL)<\/li>\n<\/ol>\n\n<\/div>\n\t\t<\/div>\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color wp-elements-23fac1582b461e9e8f892b351313494b\" style=\"color:#e46618;font-size:25px\">4.2 For static websites that use .php files (static pages)<\/h3>\n\n\n\n<p>If your website is a static website that uses .php files (such as index.php, about.php, contact.php), the method for creating a sitemap.xml is similar to the .html case, except that we have to pull the .php file instead.<\/p>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#faf2e5\" data-no-translation=\"\" data-no-auto-translation=\"\"><code><strong><em>\/index.php\n\/about.php\n\/contact.php\n\/blog.php\n\/products\/product1.php\n\/products\/product2.php<\/em><\/strong><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Python code for creation <code>sitemap.xml<\/code> From file <code>.php<\/code><\/h5>\n\n\n\n<pre class=\"wp-block-code has-layout-color has-primary-background-color has-text-color has-background has-link-color wp-elements-74b54ea1680cc10c12d5aa3f118addb8\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>import os, datetime\n\n\ndomain = \"https:\/\/yourdomain.com\"\nweb_dir = \".\/public_html\" \ntoday = datetime.date.today().isoformat()\n\nurls = &#91;]\n\n\nfor root, dirs, files in os.walk(web_dir):\n    for file in files:\n        if file.endswith(\".php\"):\n            rel_path = os.path.relpath(os.path.join(root, file), web_dir)\n            url = \"\/\" + rel_path.replace(\"\\\\\", \"\/\")\n            if url.endswith(\"index.php\"):\n                url = url.replace(\"index.php\", \"\")\n            urls.append(url)\n\n\nsitemap_path = os.path.join(web_dir, \"sitemap.xml\")\nwith open(sitemap_path, \"w\", encoding=\"utf-8\") as f:\n    f.write('&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\\n')\n    f.write('&lt;urlset xmlns=\"http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9\"&gt;\\n')\n    for url in urls:\n        f.write(\"  &lt;url&gt;\\n\")\n        f.write(f\"    &lt;loc&gt;{domain}{url}&lt;\/loc&gt;\\n\")\n        f.write(f\"    &lt;lastmod&gt;{today}&lt;\/lastmod&gt;\\n\")\n        f.write(\"    &lt;changefreq&gt;monthly&lt;\/changefreq&gt;\\n\")\n        f.write(\"    &lt;priority&gt;0.5&lt;\/priority&gt;\\n\")\n        f.write(\"  &lt;\/url&gt;\\n\")\n    f.write(\"&lt;\/urlset&gt;\\n\")\n\nprint(\"Sitemap index created successfully!\")<\/code><\/pre>\n\n\n<div class=\"gc-box notice_type icon_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><svg x=\"0px\" y=\"0px\" viewbox=\"0 0 486.463 486.463\" > <g> <g> <path d=\"M243.225,333.382c-13.6,0-25,11.4-25,25s11.4,25,25,25c13.1,0,25-11.4,24.4-24.4 C268.225,344.682,256.925,333.382,243.225,333.382z\"\/> <path d=\"M474.625,421.982c15.7-27.1,15.8-59.4,0.2-86.4l-156.6-271.2c-15.5-27.3-43.5-43.5-74.9-43.5s-59.4,16.3-74.9,43.4 l-156.8,271.5c-15.6,27.3-15.5,59.8,0.3,86.9c15.6,26.8,43.5,42.9,74.7,42.9h312.8 C430.725,465.582,458.825,449.282,474.625,421.982z M440.625,402.382c-8.7,15-24.1,23.9-41.3,23.9h-312.8 c-17,0-32.3-8.7-40.8-23.4c-8.6-14.9-8.7-32.7-0.1-47.7l156.8-271.4c8.5-14.9,23.7-23.7,40.9-23.7c17.1,0,32.4,8.9,40.9,23.8 l156.7,271.4C449.325,369.882,449.225,387.482,440.625,402.382z\"\/> <path d=\"M237.025,157.882c-11.9,3.4-19.3,14.2-19.3,27.3c0.6,7.9,1.1,15.9,1.7,23.8c1.7,30.1,3.4,59.6,5.1,89.7 c0.6,10.2,8.5,17.6,18.7,17.6c10.2,0,18.2-7.9,18.7-18.2c0-6.2,0-11.9,0.6-18.2c1.1-19.3,2.3-38.6,3.4-57.9 c0.6-12.5,1.7-25,2.3-37.5c0-4.5-0.6-8.5-2.3-12.5C260.825,160.782,248.925,155.082,237.025,157.882z\"\/> <\/g> <\/g> <\/svg><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h4 class=\"wp-block-heading\">\ud83d\udd39 Usage<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Place this script file in your project folder (e.g. <code>generate_sitemap.py<\/code>)<\/li>\n\n\n\n<li>Run with <code>python generate_sitemap.py<\/code><\/li>\n\n\n\n<li>You will get the file <code>sitemap.xml<\/code> Located at the root (<code>public_html\/sitemap.xml<\/code>)<\/li>\n\n\n\n<li>Try opening it in a browser \u2192 <code>https:\/\/<code>yourdomain<\/code>.com\/sitemap.xml<\/code><\/li>\n\n\n\n<li>Take it away <strong>Submit to Google Search Console \/ Bing Webmaster<\/strong><\/li>\n<\/ol>\n\n<\/div>\n\t\t<\/div>\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-1d0e923835c66ddc8b439676f1ae128f\" style=\"color:#1a8079;font-size:30px\">5. Create a sitemap.xml for <strong>Shared Hosting<\/strong><\/h2>\n\n\n\n<p>If you are using Shared Hosting, which is limited by the fact that you are not allowed to run Python files directly on shared hosting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color wp-elements-6fb5bfe6424542ff38b624517cb57c7c\" style=\"color:#e46618;font-size:27px\">So, there are two options for automatically generating sitemap.xml.<\/h3>\n\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:0px;\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h4 class=\"wp-block-heading has-text-color has-link-color wp-elements-2c8640e04290cf046f65eb1aea749dff\" style=\"color:#922dae;font-size:20px\">\ud83d\udd39 Option 1 (easiest) \u2014 Use your local machine to create and upload.<\/h4>\n\n\n\n<p><strong>Install Python on your machine<\/strong> (Windows\/Mac)<\/p>\n\n\n\n<p>Run the Python script \u2192 you will get a file <code>sitemap.xml<\/code><\/p>\n\n\n\n<p>Open Command Prompt (Windows) or Terminal (Mac\/Linux) and type:<\/p>\n\n\n\n<pre class=\"wp-block-code has-primary-color has-orange-background-color has-text-color has-background has-link-color wp-elements-22700d9d69990481ae4f3467d652115e\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>python generate_sitemap.py<\/code><\/pre>\n\n\n\n<p>Upload file <code>sitemap.xml<\/code> Go to <code>public_html\/<\/code> of hosting through <strong>File Manager \/ FTP<\/strong><\/p>\n\n\n\n<p>Go to the browser \u2192<\/p>\n\n\n\n<pre class=\"wp-block-code has-primary-color has-orange-background-color has-text-color has-background has-link-color wp-elements-4c40ab6e95de4767b35e8fb6aea06158\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>https:&#47;&#47;yourdomain.com\/sitemap.xml<\/code><\/pre>\n\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:0px;\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h4 class=\"wp-block-heading has-text-color has-link-color wp-elements-c60cce5e7233d756e1a3bfa2ac3acf73\" style=\"color:#922dae;font-size:20px\">\ud83d\udd39 Option 2 \u2014 Use PHP to create a Sitemap on your Hosting.<\/h4>\n\n\n\n<p>If you don&#039;t want to run Python locally, you can write PHP code to automatically generate a sitemap.xml.<\/p>\n\n\n\n<pre class=\"wp-block-code has-layout-color has-primary-background-color has-text-color has-background has-link-color wp-elements-cc889b7e760069b369c38ad22f15fc95\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>&lt;?php\n$domain = \"https:\/\/yourdomain.com\";\n$web_dir = __DIR__; \/\/ public_html\n$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($web_dir));\n$urls = &#91;];\n\nforeach ($files as $file) {\n    if ($file-&gt;isFile() &amp;&amp; pathinfo($file, PATHINFO_EXTENSION) === \"php\") {\n        $path = str_replace($web_dir, \"\", $file-&gt;getPathname());\n        $url = str_replace(\"\\\\\", \"\/\", $path);\n        if (basename($url) === \"index.php\") {\n            $url = str_replace(\"index.php\", \"\", $url);\n        }\n        $urls&#91;] = $url;\n    }\n}\n\n$today = date(\"Y-m-d\");\n$sitemap = '&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;' . \"\\n\";\n$sitemap .= '&lt;urlset xmlns=\"http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9\"&gt;' . \"\\n\";\n\nforeach ($urls as $url) {\n    $sitemap .= \"  &lt;url&gt;\\n\";\n    $sitemap .= \"    &lt;loc&gt;{$domain}{$url}&lt;\/loc&gt;\\n\";\n    $sitemap .= \"    &lt;lastmod&gt;{$today}&lt;\/lastmod&gt;\\n\";\n    $sitemap .= \"    &lt;changefreq&gt;monthly&lt;\/changefreq&gt;\\n\";\n    $sitemap .= \"    &lt;priority&gt;0.5&lt;\/priority&gt;\\n\";\n    $sitemap .= \"  &lt;\/url&gt;\\n\";\n}\n\n$sitemap .= \"&lt;\/urlset&gt;\";\n\nfile_put_contents($web_dir . \"\/sitemap.xml\", $sitemap);\n\necho \"\u2705 Sitemap created at {$domain}\/sitemap.xml\";\n?&gt;\n<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\">\ud83d\udd39 Usage<\/h6>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Save as file <code>generate_sitemap.php<\/code><\/li>\n\n\n\n<li>Upload to <code>public_html\/<\/code><\/li>\n\n\n\n<li>Call files via the web, such as:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-orange-background-color has-background\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>https:&#47;&#47;yourdomain.com\/generate_sitemap.php<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You will get the file <code>sitemap.xml<\/code> Immediately at root<\/li>\n<\/ul>\n\n<\/div>\n\t\t<\/div>\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box border_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-f241334b63c73b813a8ec88f8f54ab0a\" style=\"color:#1a8079;font-size:33px\">6. There is a new sitemap.xml page that is automatically updated.<\/h2>\n\n\n\n<p>You want to give <strong>When a new page is added (.php)<\/strong> \u2192 <code>sitemap.xml<\/code> It is updated automatically, since Python cannot be run directly, we will use a PHP script to check the .php file in public_html every time and write a new sitemap.xml.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-color has-link-color wp-elements-fdae2986c5d64973b5dbb69f9e471117\" style=\"color:#e46618;font-size:25px\">PHP Code: Auto Generate Sitemap Every Time It Runs<\/h3>\n\n\n\n<pre class=\"wp-block-code has-layout-color has-primary-background-color has-text-color has-background has-link-color wp-elements-eb766c9d57cc70511bd3982919b13d59\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>&lt;?php\n\n$domain = \"https:\/\/yourdomain.com\";\n$web_dir = __DIR__; \/\/ public_html\n$today = date(\"Y-m-d\");\n\n$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($web_dir));\n$urls = &#91;];\n\nforeach ($files as $file) {\n    if ($file-&gt;isFile() &amp;&amp; pathinfo($file, PATHINFO_EXTENSION) === \"php\") {\n        $path = str_replace($web_dir, \"\", $file-&gt;getPathname());\n        $url = str_replace(\"\\\\\", \"\/\", $path);\n\n        if (basename($url) === \"index.php\") {\n            $url = str_replace(\"index.php\", \"\", $url);\n        }\n\n        $urls&#91;] = $url;\n    }\n}\n\n\/\/  sitemap.xml\n$sitemap = '&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;' . \"\\n\";\n$sitemap .= '&lt;urlset xmlns=\"http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9\"&gt;' . \"\\n\";\n\nforeach ($urls as $url) {\n    $sitemap .= \"  &lt;url&gt;\\n\";\n    $sitemap .= \"    &lt;loc&gt;{$domain}{$url}&lt;\/loc&gt;\\n\";\n    $sitemap .= \"    &lt;lastmod&gt;{$today}&lt;\/lastmod&gt;\\n\";\n    $sitemap .= \"    &lt;changefreq&gt;monthly&lt;\/changefreq&gt;\\n\";\n    $sitemap .= \"    &lt;priority&gt;0.5&lt;\/priority&gt;\\n\";\n    $sitemap .= \"  &lt;\/url&gt;\\n\";\n}\n\n$sitemap .= \"&lt;\/urlset&gt;\";\n\nfile_put_contents($web_dir . \"\/sitemap.xml\", $sitemap);\n\necho \"\u2705 Sitemap updated at {$domain}\/sitemap.xml\";\n?&gt;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\ud83d\udd39 How to use<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Upload the generate_sitemap.php file to public_html.<\/li>\n\n\n\n<li>Call the file in the browser:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-primary-color has-orange-background-color has-text-color has-background has-link-color wp-elements-ec72b115d2d962a048550e6f74b47b85\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>https:&#47;&#47;yourdomain.com\/generate_sitemap.php<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u2192 It will regenerate (or update) the sitemap.xml every time.<\/li>\n\n\n\n<li>When adding a new .php file \u2192 just run this file again and it will update the sitemap.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">\ud83d\udd39Make it truly Auto (set up a Cron Job, no need to press it yourself)<\/h4>\n\n\n\n<p>You can use Hosting&#039;s Cron Job, for example, to run generate_sitemap.php daily\/weekly.<\/p>\n\n\n\n<p>In Hosting hPanel:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to <strong>Advanced \u2192 Cron Jobs<\/strong><\/li>\n\n\n\n<li>Add a Cron Job such as: <code>php \/home\/username\/public_html\/generate_sitemap.php<\/code> <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-primary-color has-text-color has-background has-link-color wp-elements-9fba2ebe1fe4129b94a707cbf2e9fc67\" style=\"background-color:#c8e5ea\" data-no-translation=\"\" data-no-auto-translation=\"\"><code>php \/home\/username\/public_html\/generate_sitemap.php<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Then set the time to <strong>Once a day<\/strong><\/li>\n<\/ul>\n\n<\/div>\n\t\t<\/div>\n\n<div class=\"gc-box notice_type icon_type\" style=\"text-align:left;border-radius:20px;box-shadow: 0 10px 10px #00000007\">\n\t\t\t<div class=\"gc-box-icon\"><svg x=\"0px\" y=\"0px\" viewbox=\"0 0 486.463 486.463\" > <g> <g> <path d=\"M243.225,333.382c-13.6,0-25,11.4-25,25s11.4,25,25,25c13.1,0,25-11.4,24.4-24.4 C268.225,344.682,256.925,333.382,243.225,333.382z\"\/> <path d=\"M474.625,421.982c15.7-27.1,15.8-59.4,0.2-86.4l-156.6-271.2c-15.5-27.3-43.5-43.5-74.9-43.5s-59.4,16.3-74.9,43.4 l-156.8,271.5c-15.6,27.3-15.5,59.8,0.3,86.9c15.6,26.8,43.5,42.9,74.7,42.9h312.8 C430.725,465.582,458.825,449.282,474.625,421.982z M440.625,402.382c-8.7,15-24.1,23.9-41.3,23.9h-312.8 c-17,0-32.3-8.7-40.8-23.4c-8.6-14.9-8.7-32.7-0.1-47.7l156.8-271.4c8.5-14.9,23.7-23.7,40.9-23.7c17.1,0,32.4,8.9,40.9,23.8 l156.7,271.4C449.325,369.882,449.225,387.482,440.625,402.382z\"\/> <path d=\"M237.025,157.882c-11.9,3.4-19.3,14.2-19.3,27.3c0.6,7.9,1.1,15.9,1.7,23.8c1.7,30.1,3.4,59.6,5.1,89.7 c0.6,10.2,8.5,17.6,18.7,17.6c10.2,0,18.2-7.9,18.7-18.2c0-6.2,0-11.9,0.6-18.2c1.1-19.3,2.3-38.6,3.4-57.9 c0.6-12.5,1.7-25,2.3-37.5c0-4.5-0.6-8.5-2.3-12.5C260.825,160.782,248.925,155.082,237.025,157.882z\"\/> <\/g> <\/g> <\/svg><\/div>\n\t\t\t\n\t\t\t<div class=\"gc-box-text\">\n\n<p>It is recommended to manage Sitemaps using a Sitemap index file. When a Sitemap exceeds the size limit, it is recommended to split it into multiple files and use the index file to submit up to 500 files per site simultaneously in Search Console. The XML format of the index file is similar to a normal Sitemap and must be located in the same directory or deeper.<\/p>\n\n\n\n<p>More information <a href=\"https:\/\/developers.google.com\/search\/docs\/crawling-indexing\/sitemaps\/large-sitemaps\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developers.google.com<\/a><\/p>\n\n<\/div>\n\t\t<\/div>\n\n<style scoped>.gc-accordion{margin-bottom:25px}.gc-accordion .gc-accordion-item{margin:10px 0 0}.gc-accordion .gc-accordion-item.gcclose .gc-accordion-item__content{display:none}.gc-accordion .gc-accordion-item.gcopen .gc-accordion-item__title .gciconafter{transform:rotate(0)}.gc-accordion .gc-accordion-item:first-of-type{margin-top:0}.gc-accordion .gc-accordion-item__heading{outline:0;text-decoration:none;font-weight:400 !important;font-size:15px !important;line-height:21px !important;margin:0 !important;padding:15px !important;}.gc-accordion .gc-accordion-item__title{z-index:1;position:relative;display:block;margin:0;background:none #f9f9f9;border:1px solid #ddd;cursor:pointer;transition:all .3s ease-in-out}.gc-accordion .gc-accordion-item__title span.iconfortoggle{display:block;position:absolute;height:14px;width:14px;right:20px;top:18px}.gc-accordion .gc-accordion-item__title span.iconfortoggle .gciconbefore{content:\"\";width:14px;height:3px;border-radius:2px;background-color:#111;position:absolute;top:6px}.gc-accordion .gc-accordion-item__title span.iconfortoggle .gciconafter{content:\"\";width:14px;height:3px;border-radius:2px;background-color:#111;position:absolute;top:6px;transform:rotate(90deg);transition:all .3s ease-in-out}.gc-accordion .gc-accordion-item__title:hover{background:none #eee}.gc-accordion .gc-accordion-item__content{z-index:0;position:relative;padding:15px;border:1px solid #ddd;border-top:none;background:#fff}.gc-accordion .gc-accordion-item__content.stuckMoveDownOpacity{-webkit-animation:stuckMoveDownOpacity .6s;animation:stuckMoveDownOpacity .6s}.gc-accordion .gc-accordion-item__text{font-size:16px;font-weight:400;line-height:1.75}@keyframes stuckMoveDownOpacity{0%{transform:translateY(-15px);opacity:0}100%{transform:translateY(0);opacity:1}}<\/style><div class=\"gc-accordion\" itemscope=\"\" itemtype=\"https:\/\/schema.org\/FAQPage\"><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">What is Sitemap.xml?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">An XML file that tells Google and search engines which pages are included, along with ranking information such as last modified date (lastmod), change frequency (changefreq), and priority (priority).<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">Is a sitemap.xml required?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">It&#039;s not required, but it helps search engines index your pages faster, especially for larger sites or sites with frequent new pages added.<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">How is Sitemap.xml different from robots.txt?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">robots.txt \u2192 tells search engines which pages to block access; sitemap.xml \u2192 tells search engines which pages are included and should be indexed.<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">Can PHP\/HTML websites use sitemap.xml?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">Sure! Sitemap.xml doesn&#039;t care if the file is PHP, HTML, or a dynamic URL, it just tells you the URL of the web page.<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">How often should I update my sitemap.xml?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">If new pages are added frequently \u2192 you should update them immediately * If the website is stable \u2192 update when there are changes<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">Is sitemap.xml too large?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">Maximum XML file size = 50MB, maximum 50,000 URLs per file. If more than this \u2192 split into multiple files and create a sitemap index.<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">Can dynamic URLs (such as query strings) be included in sitemaps?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">You can, but you should use URLs that Google can actually index and avoid URLs that create duplicate content.<\/div><\/div><\/div><div class=\"gc-accordion-item gcopen\" itemscope=\"\" itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\"><div class=\"gc-accordion-item__title\" style=\"background-color:#c6e3f7;border-color:#c6e3f7;\"><h3 class=\"gc-accordion-item__heading\" itemprop=\"name\" style=\"\">How to automatically generate a sitemap.xml?<\/h3><span class=\"iconfortoggle\"><span class=\"gciconbefore\" style=\"\"><\/span><span class=\"gciconafter\" style=\"\"><\/span><\/span><\/div><div class=\"gc-accordion-item__content\" style=\"\" itemscope=\"\" itemprop=\"acceptedAnswer\" itemtype=\"https:\/\/schema.org\/Answer\"><div class=\"gc-accordion-item__text\" itemprop=\"text\">Use PHP script (suitable for Shared Hosting) Use Python \/ External Script and upload it Use Plugin \/ CMS such as WordPress has a generator provided.<\/div><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"Creating a sitemap.xml file with Python code step by step to help search engines know our web pages. There is an example for a static website that uses .html and .php files, along with instructions on how to use it and send it to Google &amp; Bing via Search Console or ping URL.","protected":false},"author":1,"featured_media":2746,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[23,28],"tags":[],"class_list":{"0":"post-2699","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-website-creation","8":"category-html-css-javascript","9":"cs-entry"},"_links":{"self":[{"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/posts\/2699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/comments?post=2699"}],"version-history":[{"count":36,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/posts\/2699\/revisions"}],"predecessor-version":[{"id":2741,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/posts\/2699\/revisions\/2741"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/media\/2746"}],"wp:attachment":[{"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/media?parent=2699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/categories?post=2699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/siammakemoney.com\/en\/wp-json\/wp\/v2\/tags?post=2699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}