Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter lonewulf79

    (@lonewulf79)

    Hello,

    please disregard. Thanks.

    Regards,

    Dejan

    Thread Starter lonewulf79

    (@lonewulf79)

    Hello,

    please disregard. Thanks.

    Regards,

    Dejan

    • This reply was modified 2 years ago by lonewulf79.
    Thread Starter lonewulf79

    (@lonewulf79)

    Hi,

    well, site is about art and there are thousands of images and more every day. It’s not really practical manually adding images one by one. How does this actually effect eg. search engines?

    Dejan

    Thread Starter lonewulf79

    (@lonewulf79)

    Yes, thank you for that code. I actually managed to scrap my way to retrieving the data I wanted, but your code seems more streamlined 🙂

    As you say, what to do with that info next? Good news, again after a lot of stubbornness and with the help of this code I found https://brutalbusiness.com/automatically-set-the-wordpress-image-title-alt-text-other-meta , resulted in something like this code below. It goes to theme’s functions.php.

    There are still comments and unused lines and whatnot but hopefully if somebody finds it useful they can edit it for their needs.

    Upon uploading an image or multiple images, doesn’t matter, it populates, in this case description field, with image dimensions, file size and type.

    Regards.

    /* Automatically set the image Title, Alt-Text, Caption & Description upon upload
    --------------------------------------------------------------------------------------*/
    add_action( 'add_attachment', 'my_set_image_meta_upon_image_upload' );
    function my_set_image_meta_upon_image_upload( $post_ID ) {
    
    	//$my_image_title = get_post( $post_ID )->ID;
    	$array_image = getimagesize(get_attached_file( $post_ID ));
    		
    	// Sanitize the title:  remove hyphens, underscores & extra spaces:
    	//$my_image_title = preg_replace( '%\s*[-_\s]+\s*%', ' ',  $my_image_title );
    
    	// Sanitize the title:  capitalize first letter of every word (other letters lower case):
    	//$my_image_title = ucwords( strtolower( $my_image_title ) );
    	
    	$filesize = size_format(filesize(get_attached_file( $post_ID )));
    
    	$mime = strtoupper(substr($array_image['mime'], 6));
    	
    	if ($mime == "JPEG") {
    		
    		$mime = strtoupper(substr($array_image['mime'], 6, 2). substr($array_image['mime'], 9, 1));
    		
    		} else {
    		
    		$mime = strtoupper(substr($array_image['mime'], 6));
    		
    		}
    	
    	//$time = date("d-M-y", filectime(get_attached_file( $post_ID )));
    		
    		// Create an array with the image meta (Title, Caption, Description) to be updated
    		// Note:  comment out the Excerpt/Caption or Content/Description lines if not needed
    		$my_image_meta = array(
    			'ID'		=> $post_ID,			// Specify the image (ID) to be updated
    			//'post_title'	=> $my_image_title,		// Set image Title to sanitized title
    			//'post_excerpt'	=> $my_image_title,		// Set image Caption (Excerpt) to sanitized title
    			'post_content'	=> "<p>" . $array_image[0] . " x " . $array_image[1] . "</p>" . "\n" . "<p>" . $filesize . " " . $mime . "</p>"// . "\n" . "<p>" . $time . "</p>",		// Set image Description (Content) to sanitized 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 );
    
    	//} 
    }
    • This reply was modified 2 years, 7 months ago by lonewulf79.
    • This reply was modified 2 years, 7 months ago by lonewulf79.
    Thread Starter lonewulf79

    (@lonewulf79)

    Yes, images are uploaded into media library. Well, this is currently above my head, so I guess I’ll have to learn how to use that.

    Couldn’t one just use eg. EXIF plugin code that does input info to caption?

    If you could maybe just advise one or two steps on how to proceed with info you have provided. It would be much appreciated. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)