Skip to content

Instantly share code, notes, and snippets.

@probaldhar
Created November 6, 2015 07:48
Show Gist options
  • Save probaldhar/ce5ca6a74075c93af101 to your computer and use it in GitHub Desktop.
Save probaldhar/ce5ca6a74075c93af101 to your computer and use it in GitHub Desktop.
Getting ID of page or post in wordpress
// Sometimes it's got really hard to get ID of a post or page in the starting of functions.php because then wp_query was not fired,
// so to getting any page ID or post ID in that situation you can use this code.
$url = explode('?', 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$ID = url_to_postid($url[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment