Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get post/term slug from any type of URL
//Examples of input
$input = "";
$input = "";
$input = "";
$input = "";
//This line will always return "slug"
$slug = basename(strtok(str_replace(' ', '', htmlspecialchars($input )), '?')).PHP_EOL;
echo $slug;
//Useful for further use with get_term_by('slug', $slug, $tax);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.