Answer the question
In order to leave comments, you need to log in
How can I automatically add alt to images when they are uploaded?
That is, when loading, and not on the fly, for example, by the title of the entry into which the image is loaded.
What would then be the opportunity to edit it (alt).
Answer the question
In order to leave comments, you need to log in
function set_image_alt_on_upload( $post_ID ) {
if ( wp_attachment_is_image( $post_ID ) ) {
$attachment = get_post( $post_ID );
$parent_post = get_post( $attachment->post_parent );
update_post_meta( $post_ID, '_wp_attachment_image_alt', $parent_post->post_title );
}
}
add_action( 'add_attachment', 'set_image_alt_on_upload' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question