Created
November 6, 2015 07:48
-
-
Save probaldhar/ce5ca6a74075c93af101 to your computer and use it in GitHub Desktop.
Getting ID of page or post in wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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