WordPress generating Undefined Variable warning

As the warnings say, $post is used but not defined, hence “Undefined variable $post” and then ‘Attempt to read property “ID” on null’. It seems like the global $post is in an erroneous location and should be before the if statement:

global $post;
if ( is_singular() && wp_attachment_is_image ( $post->ID ) )

You may also wish to guard against the case of if $post is empty, using the nullsafe operator:

if ( is_singular() && wp_attachment_is_image ( $post?->ID ) )

Or perhaps better yet, do the is_singular() check before accessing $post at all, since $post should be defined if is_singular() is true:

if ( is_singular() ) {
  global $post;
  if ( wp_attachment_is_image( $post->ID ) ) {
    wp_enqueue_script( 'keyboard-image-navigation', get_stylesheet_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );

techhipbettruvabetnorabahisbahis forumutaraftarium24eduedueduseduedusedusedusedusedusedus