Automatic Set Image/Thumbnail ALT Name without Plugins
Automatic Set Image/Thumbnail ALT Name
Add code on your WordPress theme and make functionality to set automatically ALT name in all type of uploaded image like featured image or post image.
// Automatic image ALT name function auto_image_alt_name( $post_ID ) { if ( wp_attachment_is_image( $post_ID ) ) { $auto_alt_image_title = get_post( $post_ID )->post_title; $new_alt_name = wp_trim_words( $auto_alt_image_title, 6, $more = ' Thumbnail' ); update_post_meta( $post_ID, '_wp_attachment_image_alt', $new_alt_name ); } } add_action( 'add_attachment', 'auto_image_alt_name' );
Paste this code on functions.php. Thanks for visiting.