Missing featured image alt text

Question

I’m using this code to add the alt text to my featured images on upload.

$image_title = get_post( $post->ID )->post_title;
// Sanitize the title:  remove hyphens, underscores & extra spaces:
$image_title = preg_replace( '%s*[-_s]+s*%', ' ',  $image_title );
// Sanitize the title:  capitalize first letter of every word (other letters lower case):
$image_title = ucwords( strtolower( $image_title ) );
// Set the image Alt-Text
add_post_meta( $post->ID, '_wp_attachment_image_alt', $image_title );

It’s working and I can see it on it’s database table wp_postmeta under it’s post ID.

Altough it’s correctly registred on the database, the featured image doesn’t have the Alt text (see the image bellow)

missing Alt Text

What could be the problem?

0
bpy 3 years 2019-10-30T15:26:09-05:00 0 Answers 73 views 0

Leave an answer

Browse
Browse