Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Forked from davidpaulsson/wp-get_id_by_slug
Created September 1, 2017 12:53
Show Gist options
  • Save gagimilicevic/422d5def7613531fe9c779cad8201ec4 to your computer and use it in GitHub Desktop.
Save gagimilicevic/422d5def7613531fe9c779cad8201ec4 to your computer and use it in GitHub Desktop.
WordPress: Get page ID from slug
// Usage:
// get_id_by_slug('any-page-slug');
function get_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment