PHP Text Menu 1.0

A lightweight, database-free navigation component for PHP websites. Menu content lives in an indented text file, nested sections use native HTML details elements, and the included JavaScript remembers section and scroll state in the browser.

Requirements

Installation

  1. Copy menu.php, menu.css, menu.js, and menu.txt into your project.

  2. Load menu.css in the page head.

  3. Set $textMenuConfig and include menu.php where the navigation should appear.

  4. Load menu.js near the end of the page body.

Open demo.php through a PHP web server to see a complete example.

Configuration

OptionDefaultPurpose
titleSite MenuVisible navigation heading
aria_labelPrimary navigationAccessible navigation label
idtext-menu-navigationNavigation element ID
filePackage menu.txtMenu configuration path
base_urlEmptyPrefix for relative menu URLs
storage_keyphp-text-menuUnique browser-storage namespace
toggle_labelMenuMobile toggle text
external_new_tabtrueOpen HTTP(S) links in a new tab

If a page contains more than one menu, give each one a unique id and storage_key.

Custom styling

Override these CSS custom properties on .tm-menu:

The mobile layout activates below 760 pixels. Adjust the matching media queries in menu.css and menu.js together if your site uses a different breakpoint.