{"id":1538,"date":"2020-10-16T21:05:20","date_gmt":"2020-10-16T15:35:20","guid":{"rendered":"https:\/\/imageattributespro.com\/?p=1538"},"modified":"2020-10-16T21:05:22","modified_gmt":"2020-10-16T15:35:22","slug":"rename-image-alt-text-title-in-bulk","status":"publish","type":"post","link":"https:\/\/imageattributespro.com\/rename-image-alt-text-title-in-bulk\/","title":{"rendered":"Rename Image Alt Text or Image Title Automatically in Bulk"},"content":{"rendered":"\n

Let’s assume that you have a need to rename (or replace) a specific phrase or word in all your image attributes across your website. Image Attributes Pro<\/a> can help!<\/p>\n\n\n\n

For example, you had appended your business name along with all your image filenames. You had used this filename to generate image attributes. Now you rebranded and you wish to change the attributes sitewide with the new business name. <\/p>\n\n\n\n

Please note<\/strong>: Image Attributes Pro does not rename the actual images yet (as of version 1.3). This doc is about renaming the image attributes and not the filename.<\/p>\n\n\n\n

To do so, we will take advantage of the iaffpro_image_attributes<\/a> WordPress filter in the pro add-on. If code isn’t your think, don’t panic and read on, there is a easy to use code snippet with clear instructions below. <\/p>\n\n\n\n

Example Snippet<\/h2>\n\n\n\n

For this example, we have an image that is title old-small-business.jpg<\/code>. Image Attributes are generated from the image filename and will all contain Old Small Business<\/code> in it. <\/p>\n\n\n\n

You have rebranded to your new business name, New Flashy Business<\/code>. Here is the code sample that will replace the the old phrase with the new. <\/p>\n\n\n\n

Add this to the functions.php<\/code> of your active theme and then run the Bulk Updater on all images. <\/p>\n\n\n\n

Important!<\/strong> Please remember to take a full database backup and run a test update (using the Test Bulk Updater<\/code> button) before doing this. Changes once made cannot be automatically undone without a database backup. <\/p>\n\n\n\n

\/**\n * Modify image attributes generated by Image Attributes Pro\n *\n * @param $attributes \t\t(array) Associative array of image attributes.\n * @param $image_id \t\t(int) ID of the current image.\n * @param $parent_post_id\t(int) ID of the post the image is inserted into. 0 for images not attached to a post.\n * \n * @author Arun Basil Lal\n * @link https:\/\/imageattributespro.com\/codex\/iaffpro-image-attributes\/\u200e\n *\/\n function prefix_iap_modify_image_attributes( $attributes, $image_id, $parent_post_id ) {\n\t\n\tforeach ( $attributes as $key => $attribute ) {\n\t\t\n\t\t$attributes[$key] = str_ireplace( 'Old Small Business', 'New Flashy Business', $attribute );\n\t}\n\t\n\treturn $attributes;\n}\nadd_filter( 'iaffpro_image_attributes', 'prefix_iap_modify_image_attributes', 10, 3 );<\/code><\/pre>\n\n\n\n

Please note:<\/strong><\/p>\n\n\n\n