iaffpro_safe_words_in_filename

This filter introduced in Image Attributes Pro version 4.9 will allow users to specify words or phrases that should remain completely unchanged during filename cleanup and image attribute generation.

This is useful to:

  • Preserve hyphenated words (e.g. USB-C, Wi-Fi).
  • Keep technical terms or other special words intact (e.g. WordPress).
  • You want to prevent certain words from being affected by character removal or regex rules.
/**
* Define Safe Words that should remain intact during filename processing.
*
* Safe Words are preserved before Image Attributes Pro applies any filters, 
* and are restored afterward without modification.
*
* @since 4.9
*
* @param (array) $safe_words List of words to preserve.
*/
$safe_words = apply_filters( 'iaffpro_safe_words_in_filename', array() );

Lower and upper cases of the words must be specified separately. For example, wi-fi and Wi-Fi. The words specified are exempted from all filters and capitalization settings.

Example Usage

Let’s consider a case where we want to preserve the capitalization of the word WordPress and the hyphen in the word TP-Link.

To do that, add the following code to the functions.php of your active theme or any snippet plugin.

/**
 * Specify words to preserve in image filename.
 * 
 * The following words will not be subject to Image Attributes Pro's filters. 
 * For example, the hyphen in TP-Link will be preserved regardless of the 
 * filter setting in Image Attributes Pro settings to remove hyphens.
 * 
 * @link https://imageattributespro.com/codex/iaffpro_safe_words_in_filename/
 * 
 * @return (array) $safe_words List of words to preserve.
 */
function prefix_iap_words_to_preserve () {
	$safe_words = array(
		'WordPress',
		'TP-Link'
	);

	return $safe_words;
}
add_filter( 'iaffpro_safe_words_in_filename', 'prefix_iap_words_to_preserve' );

Here is an example before and after using safe words.

Before And After Safe Words In Image Attributes Pro

As you can see above, the word TP-Link is preserved, including it’s hyphen and case.

Was this article helpful?
Yes, thanks! 👍Not really 👎