/ Published in: PHP

This is a snippet to assign an active class to active links when the navigation is included in a php file.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// At the top of the page that includes the navigation: $page = basename($_SERVER['SCRIPT_NAME']); // In the navigation page that gets included:<br /> // Add in the <a> tag after the href attribute: class="<?php if ($page == example.php) { echo "active"; }; ?>"
Comments
