SHARE
TWEET

Untitled

a guest Aug 17th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** Set alt, title and description for image uploads */
  2. function set_image_meta_upload( $post_ID ) {
  3.     if ( wp_attachment_is_image( $post_ID ) ) {
  4.     $my_image_title = get_post( $post_ID )->post_title;
  5.     $my_image_title = preg_replace( '%\s*[-_\s]+\s*%', ' ',
  6.     $my_image_title );
  7.     $my_image_title = ucwords( strtolower( $my_image_title ) );
  8.     $my_image_meta = array(
  9.     'ID' => $post_ID,
  10.     'post_title' => $my_image_title,
  11.     'post_content' => $my_image_title,
  12.     );
  13.  
  14.     // Set the image Alt-Text
  15.     update_post_meta( $post_ID, '_wp_attachment_image_alt',
  16.     $my_image_title );
  17.     // Set the image meta (e.g. Title, Excerpt, Content)
  18.     wp_update_post( $my_image_meta );
  19.     }
  20. }
  21. add_action( 'add_attachment', 'set_image_meta_upload' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top