Copy Image Description To Image Alt Text In Bulk

This tutorial will help you copy WordPress image descriptions that you have set in the WordPress Media Library to Image Alt text attribute on your website using Image Attributes Pro.

Tools you need:

We will be taking advantage of the custom attributes that was introduced in Image Attributes Pro 2.0. It makes the whole process so easy.

Step 1: Define Custom Attribute Tag: %image_description%

To do so, simply copy the following code to the functions.php of your active theme.

/**
 * Custom tag %image_description% for Image Attributes Pro.
 * 
 * @param $image_id The ID of the image that is being updated. 
 * @param $parent_post_id The post to which the image is attached (uploaded) to. 
 * @param $bulk True when called from Bulk Updater. False by default.
 * 
 * @return (string) Image description from Media Library.
 * 
 * @refer https://imageattributespro.com/copy-description-to-alt-text-in-bulk/
 */
function iaffpro_get_custom_attribute_tag_image_description( $image_id, $parent_post_id, $bulk = false ) {
	
	// Read image attributes.
	$attachment = get_post( $image_id );
	
	if ( ! is_object( $attachment ) ) {
		return '';
	}

	// Return image description.
	return $attachment->post_content;
}

Step 2: Configure Bulk Updater Settings

Head over to Image Attributes Pro > Bulk Updater Settings tab.

Under General Settings, choose only Update Alt Text option.

Bulk Updater Settings Tab Configured To Update Only Image Alt Text

Scroll down to Image Alt Text Settings and configure it with the custom attribute tag: %image_description% as displayed below.

Using Image_description Custom Attribute Tag As Alt Text

You will have full flexibility on how the image alt text is updated as per the Bulk Updater Behaviour settings in Image Attributes Pro.

Bulk Updater Behaviour For Alt Text In Image Attributes Pro

Available options:

  • You can update image alt text just in the Media Library only.
  • You can update image alt text in both Media Library and within post HTML.
  • You can update image alt text in media library and posts only when the alt text is empty. This option will preserve any existing alt text that you might have.
  • A secret option: You can use the iaffpro_update_media_library filter to disable updating the Media library completely. This way only Posts will be updated.

(Confused between the difference between Media Library and Posts? Then read: Understanding How WordPress Store Image Attributes.)

Step 3: Run the Bulk Updater

Head over to the Bulk Updater tab of Image Attributes Pro and click Run Bulk Updater.

Bulk Updater Tab Of Image Attributes Pro

Alternatively you can also update specific images using the Bulk Action that is available since Image Attributes Pro version 3.0.

Please remember to take a database backup before proceeding. Also take advantage of the Test Bulk Updater button to update just one image at a time and confirm the results before proceeding.

That’s it! Congrats. If you have questions, please feel free to write to me and I shall help in every way possible.