{"id":1902,"date":"2025-03-17T12:56:34","date_gmt":"2025-03-17T12:56:34","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=1902"},"modified":"2025-03-17T12:56:36","modified_gmt":"2025-03-17T12:56:36","slug":"how-to-load-common-menu-to-bulk-html-websites","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/how-to-load-common-menu-to-bulk-html-websites\/","title":{"rendered":"How to load Common Menu to bulk html websites"},"content":{"rendered":"\n<p>You can simplify your menu management across thousands of static HTML pages by using <strong>JavaScript<\/strong> or <strong>server-side includes<\/strong>. Here are a few methods:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Method 1: Use JavaScript to Load a Common Menu<\/strong><\/h3>\n\n\n\n<p>You can create a separate file (<code>menu.html<\/code>) that contains your navigation menu and use JavaScript to include it in all your pages.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Steps:<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create a file named <code>menu.html<\/code><\/strong> and add the menu code inside it: <code>&lt;ul> &lt;li>&lt;a href=\"\/about-us\/about-us.html\" target=\"_blank\">About Us&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/vision.html\" target=\"_blank\">Vision&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/ecare-planet-technology.html\" target=\"_blank\">eCarePlanet Technology&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/contact\/join-hospital-network.html\" target=\"_blank\">Join Hospital Network&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/disclaimer.html\" target=\"_blank\">Disclaimer&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/services-easy.html\" target=\"_blank\">Simple &amp; Easy Process&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/services-full-service.html\" target=\"_blank\">Services&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/services-quality.html\" target=\"_blank\">Services Quality&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/services-savings.html\" target=\"_blank\">Services Savings&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"\/about-us\/services-guarantee.html\" target=\"_blank\">Services Guarantee&lt;\/a>&lt;\/li> &lt;\/ul><\/code><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"791\" height=\"467\" src=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-5.png\" alt=\"\" class=\"wp-image-1903\" srcset=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-5.png 791w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-5-300x177.png 300w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-5-768x453.png 768w\" sizes=\"auto, (max-width: 791px) 100vw, 791px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Include it in all HTML pages using JavaScript:<\/strong> Add this code inside the <code>&lt;body><\/code> where the menu should appear: <code>&lt;div id=\"menu-placeholder\">&lt;\/div> &lt;script> fetch('\/menu.html') .then(response => response.text()) .then(data => document.getElementById('menu-placeholder').innerHTML = data) .catch(error => console.error('Error loading the menu:', error)); &lt;\/script><\/code><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"371\" src=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-6.png\" alt=\"\" class=\"wp-image-1904\" srcset=\"https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-6.png 776w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-300x143.png 300w, https:\/\/www.cmsgalaxy.com\/blog\/wp-content\/uploads\/2025\/03\/image-6-768x367.png 768w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/figure>\n\n\n\n<p>\u2705 <strong>Advantage<\/strong>: Any updates made in <code>menu.html<\/code> will automatically reflect on all pages.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>To fix the <strong>href path issue<\/strong> when including the same menu across different directories, you should use <strong>absolute paths<\/strong> or <strong>base URL settings<\/strong>. Here are two approaches:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Solution 1: Use Absolute Paths<\/strong><\/h3>\n\n\n\n<p>Instead of using <strong>relative paths<\/strong>, use <strong>absolute paths<\/strong> based on the root (<code>\/<\/code>).<\/p>\n\n\n\n<p><strong>Example:<\/strong> Change your menu links like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/about-us.html\" target=\"_blank\"&gt;About Us&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/vision.html\" target=\"_blank\"&gt;Vision&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/ecare-planet-technology.html\" target=\"_blank\"&gt;eCarePlanet Technology&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/contact\/join-hospital-network.html\" target=\"_blank\"&gt;Join Hospital Network&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/disclaimer.html\" target=\"_blank\"&gt;Disclaimer&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/services-easy.html\" target=\"_blank\"&gt;Simple &amp; Easy Process&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/services-full-service.html\" target=\"_blank\"&gt;Services&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/services-quality.html\" target=\"_blank\"&gt;Services Quality&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/services-savings.html\" target=\"_blank\"&gt;Services Savings&lt;\/a&gt;&lt;\/li&gt;\n    &lt;li&gt;&lt;a href=\"\/about-us\/services-guarantee.html\" target=\"_blank\"&gt;Services Guarantee&lt;\/a&gt;&lt;\/li&gt;\n&lt;\/ul&gt;\n<\/code><\/pre>\n\n\n\n<p>\u2705 <strong>Why?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Absolute paths (<code>\/about-us\/about-us.html<\/code>) will always resolve from the root domain, no matter where the page is located.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Solution 2: Use a <code>&lt;base&gt;<\/code> Tag in <code>&lt;head&gt;<\/code><\/strong><\/h3>\n\n\n\n<p>If you prefer to use <strong>relative paths<\/strong>, you can define a <strong>base URL<\/strong> in the <code>&lt;head&gt;<\/code> of every page.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Steps:<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Add this in the <code>&lt;head><\/code> section of your HTML files: <code>&lt;base href=\"https:\/\/www.yourwebsite.com\/\"><\/code><\/li>\n\n\n\n<li>Keep your menu links <strong>relative<\/strong>, but they will now always refer to the root: <code>&lt;ul> &lt;li>&lt;a href=\"about-us\/about-us.html\" target=\"_blank\">About Us&lt;\/a>&lt;\/li> &lt;li>&lt;a href=\"about-us\/vision.html\" target=\"_blank\">Vision&lt;\/a>&lt;\/li> &lt;\/ul><\/code><\/li>\n<\/ol>\n\n\n\n<p>\u2705 <strong>Why?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The browser will <strong>automatically resolve all links based on the <code>&lt;base><\/code> URL<\/strong>, even if you&#8217;re in a subdirectory.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Final Recommendation<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If your website is <strong>static and follows a strict folder structure<\/strong>, use <strong>absolute paths (<code>\/about-us\/about-us.html<\/code>)<\/strong>.<\/li>\n\n\n\n<li>If you have a <strong>dynamic or multi-domain setup<\/strong>, use the <strong><code>&lt;base><\/code> tag<\/strong> to simplify URL management.<\/li>\n<\/ul>\n\n\n\n<p>Either of these fixes will ensure that your navigation menu works correctly across all 1000+ pages. \ud83d\ude80<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can simplify your menu management across thousands of static HTML pages by using JavaScript or server-side includes. Here are<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1902","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/1902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=1902"}],"version-history":[{"count":1,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/1902\/revisions"}],"predecessor-version":[{"id":1905,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/1902\/revisions\/1905"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=1902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=1902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=1902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}