Active links in included navigation


/ Published in: PHP
Save to your folder(s)

This is a snippet to assign an active class to active links when the navigation is included in a php file.


Copy this code and paste it in your HTML
  1. // At the top of the page that includes the navigation:
  2. $page = basename($_SERVER['SCRIPT_NAME']);
  3.  
  4. // In the navigation page that gets included:<br />
  5.  
  6. // Add in the <a> tag after the href attribute:
  7. class="<?php if ($page == example.php) { echo "active"; }; ?>"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.