Skip to content

Instantly share code, notes, and snippets.

@IronGhost63
Created June 21, 2017 20:28
Show Gist options
  • Save IronGhost63/d8deb0ef9c5014b5c67e6af7bf76bd48 to your computer and use it in GitHub Desktop.
Save IronGhost63/d8deb0ef9c5014b5c67e6af7bf76bd48 to your computer and use it in GitHub Desktop.
add .active if current url match href
<?php
function show_url($url, $text = ''){
$current = $uri = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo '<a href="'.$url.'" '.($current == $url ? 'class="active"' : '').'>'.(empty($text) ? $url : $text).'</a>';
}
?>
<div><?php show_url('https://jirayu.in.th', 'Website'); ?></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment