iaffpro_image_attributes

Filter the generated image attributes before they are used by the bulk updater.

/**
 * Filter generated image attributes
 * 
 * @param $attributes 		(array) Associative array of image attributes.
 * @param $image_id 		(int) ID of the current image. 
 * @param $parent_post_id	(int) ID of the post the image is inserted into. 0 for images not attached to a post. 
 * 
 * @since 1.3
 */
$attributes = apply_filters( 'iaffpro_image_attributes', $attributes, $image_id, $parent_post_id );

The $attributes is an associative array with the following array keys and values.

  • $attributes['title'] containing the image title.
  • $attributes['caption'] containing the image caption.
  • $attributes['description'] containing the description.
  • $attributes['alt_text'] containing the image alt text.

Example Usage

An example of using the filter to modify the generated image title, caption, description and alt text. Add this to the functions.php of the active theme.

/**
 * Modify image attributes generated by Image Attributes Pro
 *
 * @param $attributes 		(array) Associative array of image attributes.
 * @param $image_id 		(int) ID of the current image.
 * @param $parent_post_id	(int) ID of the post the image is inserted into. 0 for images not attached to a post.
 * 
 * @author Arun Basil Lal
 * @link https://imageattributespro.com/codex/iaffpro-image-attributes/‎
 */
 function prefix_iap_modify_image_attributes( $attributes, $image_id, $parent_post_id ) {
	
	$attributes['title'] = 'Your Title';
	$attributes['caption'] = 'Prefix For Caption - ' . $attributes['caption'];
	$attributes['description'] = 'Custom Description';
	$attributes['alt_text'] = $attributes['alt_text'] . ' - Post Fix To Alt Text';
	
	return $attributes;
}
add_filter( 'iaffpro_image_attributes', 'prefix_iap_modify_image_attributes', 10, 3 );