Skip to content

Instantly share code, notes, and snippets.

@waelio
Last active December 29, 2015 13:14
Show Gist options
  • Save waelio/2e2a12550468cb281d88 to your computer and use it in GitHub Desktop.
Save waelio/2e2a12550468cb281d88 to your computer and use it in GitHub Desktop.
Get part of the slug from the url
<?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