Last active
December 29, 2015 13:14
-
-
Save waelio/2e2a12550468cb281d88 to your computer and use it in GitHub Desktop.
Get part of the slug from the url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param int $position | |
* @param bool|true $echo | |
* @return bool | |
*/ | |
function the_slug($position=1,$echo=false){ | |
$url = parse_url($_SERVER['REQUEST_URI']); | |
$slugs = array_filter(explode('/',$url['path'])); | |
if($echo) | |
echo (isset($slugs[$position])) ? $slugs[$position] : false; | |
return (isset($slugs[$position])) ? $slugs[$position] : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment