Skip to content

Instantly share code, notes, and snippets.

@jserrao
Created January 15, 2016 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jserrao/198149dfee62c16eb84c to your computer and use it in GitHub Desktop.
Save jserrao/198149dfee62c16eb84c to your computer and use it in GitHub Desktop.
WordPress - Get Slug
// Something important to remember about WordPress is that it's functions act differently depending on your template
// This might be the single most annoying thing about WP
// You can get information out of WP but it's very situational
// 1- get the slug is with get_queried_object (on a page)
$slug = get_queried_object()->post_name;
// 2- Checkout the permalink, another way to do this (on a page)
$slug = basename(get_permalink());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment