Skip to content

Instantly share code, notes, and snippets.

@theperfectwill
Forked from eddt/wp-get_id_by_slug
Created September 6, 2016 11:48
Show Gist options
  • Save theperfectwill/4d782fed64183ce02f79b4c7762a64a1 to your computer and use it in GitHub Desktop.
Save theperfectwill/4d782fed64183ce02f79b4c7762a64a1 to your computer and use it in GitHub Desktop.
WordPress: Get page ID from slug
// Usage:
// get_id_by_slug('any-page-slug','any-post-type');
function get_id_by_slug($page_slug, $slug_page_type = 'page') {
$find_page = get_page_by_path($page_slug, OBJECT, $slug_page_type);
if ($find_page) {
return $find_page->ID;
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment