Skip to main content
Inspiring
July 3, 2017
Answered

How to move a nav menu to its own document?

  • July 3, 2017
  • 2 replies
  • 551 views

Hi,

How would I move a completed Bootstrap nav menu  out of my HTML files so it's in its own document, so that changed can be made in one place instead of having to do it on every page? JQuery? What's the best way?

Thanks.

This topic has been closed for replies.
Correct answer Nancy OShea

If PHP is available on your web hosting plan, use PHP Server-Side-Includes for your site wide navigation.

Alt-Web Design & Publishing: Server-Side Includes with PHP

Basically, 1 include file contains only the relevant HTML menu code & nothing more.   It's not a complete document, it's a code fragment.   Depending on your Bootstrap menu, you will copy & paste just the navbar code into a new file and name it navbar.html or navbar.ssi or whatever you like.

The parent pages in which the include statement occurs will need to be renamed with a .php extension.  Most shared web hosts do not parse PHP code in ordinary .html files.  If unsure, check with your hosting provider.

Nancy

2 replies

Nancy OShea
Community Expert
Nancy OSheaCommunity ExpertCorrect answer
Community Expert
July 3, 2017

If PHP is available on your web hosting plan, use PHP Server-Side-Includes for your site wide navigation.

Alt-Web Design & Publishing: Server-Side Includes with PHP

Basically, 1 include file contains only the relevant HTML menu code & nothing more.   It's not a complete document, it's a code fragment.   Depending on your Bootstrap menu, you will copy & paste just the navbar code into a new file and name it navbar.html or navbar.ssi or whatever you like.

The parent pages in which the include statement occurs will need to be renamed with a .php extension.  Most shared web hosts do not parse PHP code in ordinary .html files.  If unsure, check with your hosting provider.

Nancy

Nancy O'Shea— Product User & Community Expert
MFitz721Author
Inspiring
July 4, 2017

Thank you. Yes, my hosting company does offer .php.

For an existing site with all .html pages, including index.html, what's the best way to handle the search engines as far as them all changing to .php pages? Leave the .html pages but delete the content and have links to their .php versions? 301 Redirects?

Thanks again.

Nancy OShea
Community Expert
Community Expert
July 4, 2017

I would replace all .html files with .php.

301 Redirect old .html to new .php files.

Add a robots.txt file to your server & Disallow any folders or file types you don't want indexed.

Add a new sitemap.xml to your server with the new .php pages.

Log-in to your Google Webmaster Tools account and ask Google to re-index your site.  

Nancy

Nancy O'Shea— Product User & Community Expert
pziecina
Legend
July 3, 2017

The first thing I and most people will ask -

'Do you have PHP available on your server'?