Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created September 29, 2012 20:24
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 wesleybliss/3805104 to your computer and use it in GitHub Desktop.
Save wesleybliss/3805104 to your computer and use it in GitHub Desktop.
WordPress: Get Page ID From Slug
/**
* Get a page's ID from it's slug
*
* @param string $slug Page slug to search on
* @return null Empty on error
* @return int Page ID
*/
function get_page_ID_by_slug( $slug ) {
$page = get_page_by_path( $slug );
if ( $page ) {
return (int) $page->ID;
}
else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment