Skip to main content
1 of 2
metalzade
  • 117
  • 1
  • 2
  • 5

get_the_ID() gives notice in 404 page

I'm using get_the_ID() in my wp_enqueue_scripts action due to some needs, But as result I'm getting the following notice (wp-debug is on):

Notice: Trying to get property of non-object in C:\wamp\www\rosita\WordPress\wp-includes\post-template.php on line 29

I know why this happens, My question is why should this happen? Isn't WordPress supposed to know that there is no $post assigned to 404 and return an empty result?

Do I have to use:

if( !is_object($post) ) return;

Everywhere I use get_the_ID() in order to get rid of that Notice?

metalzade
  • 117
  • 1
  • 2
  • 5