Skip to content

Instantly share code, notes, and snippets.

@eddt
Forked from davidpaulsson/wp-get_id_by_slug
Last active December 19, 2017 08:22
Show Gist options
  • Save eddt/ee1018f26f8fc195629a to your computer and use it in GitHub Desktop.
Save eddt/ee1018f26f8fc195629a 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