Outside the Loop or out of the context of the post, such as in the header or the footer and even sidebar area in WordPress templates, the_ID() cannot be used as a function. Instead, $post->ID is used to return the post ID. $post is a global object that holds various information about the posts displayed on the page.