Created
November 5, 2023 13:48
-
-
Save finalwebsites/1ea28b5e692168620da1df44aa535495 to your computer and use it in GitHub Desktop.
Set image ALT Tag after upload via the WordPress media library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'add_attachment', 'fws_set_image_alt_after_upload' ); | |
function fws_set_image_alt_after_upload( $post_ID ) { | |
if ( wp_attachment_is_image( $post_ID ) ) { | |
$post = get_post( $post_ID ); | |
update_post_meta( $post_ID, '_wp_attachment_image_alt', $post->post_title ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use describing image names with spaces and the ALT tag is automatic set.
For example: Screenshot from the WordPress media library.jpg