iaffpro_custom_attribute_tag_trim_list

Image Attributes Pro version 4.3 and newer will trim separators like hyphen (-) and pipe symbol (|) if they appear the end of a custom generated image attribute. Any white spaces are also trimmed.

  • For instance, if you have a custom image attribute as: %posttitle% - %yoastfocuskw%.
  • Post title is Hello World.
  • The post doesn’t have a Yoast Focus Keyword.
  • Then the generated, image attribute will be Hello World - normally.
  • Image Attributes Pro will remove the orphan hyphen and turn it into Hello World.
/**
 * Filter characters to trim.
 * 
 * @since 4.3
 * 
 * @param (string) Default list of characters to trim include space, 
 * pipe symbol (|) and hyphen (-).
 */
$trim_list = apply_filters( 'iaffpro_custom_attribute_tag_trim_list', ' |-' );

Example Usage

Let’s say you use comma as a separator and want to it to be trimmed as well if it appears at the end of an image attribute. Adding the following code to the functions.php of your active theme will take care of it.

/**
 * Trim comma if it appears at the end of image attributes.
 * 
 * For Image Attributes Pro
 * 
 * @author Arun Basil Lal
 * @link https://imageattributespro.com/codex/iaffpro_custom_attribute_tag_trim_list/
 * 
 * @param $trim_list (string) Default list of characters to trim include space, 
 * pipe symbol (|) and hyphen (-).
 */
function prefix_iap_trim_comma_from_image_attributes( $trim_list ) {
	
	// Add comma to the end of existing list of characters to trim.
	$trim_list = $trim_list . ',';
	return $trim_list;
}
add_filter( 'iaffpro_custom_attribute_tag_trim_list', 'prefix_iap_trim_comma_from_image_attributes' );
Was this article helpful?
Yes, thanks! 👍Not really 👎