Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created November 5, 2023 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/1ea28b5e692168620da1df44aa535495 to your computer and use it in GitHub Desktop.
Save finalwebsites/1ea28b5e692168620da1df44aa535495 to your computer and use it in GitHub Desktop.
Set image ALT Tag after upload via the WordPress media library
<?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 );
}
}
@finalwebsites
Copy link
Author

finalwebsites commented Nov 5, 2023

Use describing image names with spaces and the ALT tag is automatic set.
For example: Screenshot from the WordPress media library.jpg

Filename to ALT tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment