iaffpro_get_custom_attribute_tag_{%tagname%}

Image Attributes Pro version 2.0 introduced custom tags that can be used to build your own custom attributes.

For example, if you want to set your image alt text as Post Title followed by Rank Math Focus Keyword, you can use %posttitle% - %rankmathfocuskw% as the custom attribute.

Image Alt Text As Post Title Rank Math Focus Keyword

Image Attributes Pro will replace %posttitle% with the title of the post to which the image is uploaded to and %rankmathfocuskw% with the focus keyword set in Rank Math plugin.

You can easily extend beyond the available tags. Let’s see that with an example.

Example: Create a tag for the name of your business

Let’s say you wish to add the name of your business as part of some of your attributes. Let’s call this tag %business_name%

Now for Image Attributes Pro to recognise this tag, you have to define a function with the name iaffpro_get_custom_attribute_tag_{%tagname%} where {%tagname%} is the name of your custom tag.

So back to our example, your function is to be named iaffpro_get_custom_attribute_tag_business_name. It would look something like this.

/**
 * Custom tag %business_name% for Image Attributes Pro
 * 
 * @return string Name of the business. 
 * 
 * @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
 */
function iaffpro_get_custom_attribute_tag_business_name() {
	return 'My Dope Business Name';
}

Add this in the functions.php of your active theme or define it in a plugin and Image Attributes Pro will replace %business_name% with My Dope Business Name while generating the image attributes.

Things To Note

  • The function must strictly be in this format: iaffpro_get_custom_attribute_tag_{%tagname%} where {%tagname%} is replaced by the name of your custom tag.
  • The function must return a string.
  • The function will have access to three parameters. $image_id, $parent_post_id, and $bulk.
  • $image_id is the ID of the image that is being updated.
  • $parent_post_id The post to which the image is attached (uploaded) to. 0 if the image is not attached to any post.
  • $bulk will be true when called from Bulk Updater. For new image uploads, it will be false.
  • Refer to \plugins\auto-image-attributes-pro\functions\custom-attributes.php for more examples.