Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Set alt, title and description for image uploads */
- function set_image_meta_upload( $post_ID ) {
- if ( wp_attachment_is_image( $post_ID ) ) {
- $my_image_title = get_post( $post_ID )->post_title;
- $my_image_title = preg_replace( '%\s*[-_\s]+\s*%', ' ',
- $my_image_title );
- $my_image_title = ucwords( strtolower( $my_image_title ) );
- $my_image_meta = array(
- 'ID' => $post_ID,
- 'post_title' => $my_image_title,
- 'post_content' => $my_image_title,
- );
- // Set the image Alt-Text
- update_post_meta( $post_ID, '_wp_attachment_image_alt',
- $my_image_title );
- // Set the image meta (e.g. Title, Excerpt, Content)
- wp_update_post( $my_image_meta );
- }
- }
- add_action( 'add_attachment', 'set_image_meta_upload' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement