get_the_post_thumbnail() alt and title attributes missing

The $attr argument to get_the_post_thumbnail() is optional, so the default value is an empty string. If it’s called with no $attr argument, it passes the same empty string through to wp_get_attachment_image(), which returns the markup for an <img> element with an empty alt attribute. This is default behaviour.

If you wanted to override this behaviour for all images, it would just be a matter of adding a filter on wp_get_attachment_image_attributes:

 function wpse426788_add_alt_text( $attr, $attachment ) {
 
    $newatts['alt'] = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', TRUE );
    
    $attr = array_merge( $attr, $newatts );
    
    return $attr;
 }
 
 add_filter( 'wp_get_attachment_image_attributes', 'wpse426788_add_alt_text', 10, 2 );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)