// 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]);