View Larger Image Add Alt to image where it’s empty in WordPress through functions.phpAdding following code to functions.php will add page title as a image alt to img tag:Copy to Clipboardfunction callback($buffer) { preg_match_all('//', $buffer, $images); if(!is_null($images)) { foreach($images[1] as $index => $value) { preg_match('/alt="(.*?)"/', $value, $img); preg_match('/alt=\"(.*?)\"/', $value, $img2); preg_match('/data-src="(.*?)"/', $value, $imgurl); $title = ""; $image_url = $imgurl[1]; //get alt from url in WordPress global $wpdb; $query_arr = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", strtolower( $image_url ) ) ); $image_id = ( ! empty( $query_arr ) ) ? $query_arr[0] : 0; $title = get_post_meta( $image_id, '_wp_attachment_image_alt', true ); // if there is no alt then get page title as alt if( empty( $title ) ) { $title = get_the_title(); } if(!is_null($images)) { if((!isset($img[1]) || $img[1] == '') || (!isset($img2[1]) || $img2[1] == '')) { $new_img = str_replace('By Mir Saeid|2020-12-10T12:38:37-05:00November 17th, 2019|Blog|0 CommentsShare This Story, Choose Your Platform!Facebook About the Author: Mir Saeid Experienced computer engineer with post graduate diploma in e-Business, Web Developer and Programmer Related Posts Redirect to a Custom Thank You Page After Checkout in WooCommerce Without Any Plugins Gallery Redirect to a Custom Thank You Page After Checkout in WooCommerce Without Any Plugins Add second description to category and shows up under products in WordPress Gallery Add second description to category and shows up under products in WordPress ajax-loader.gif problem Gallery ajax-loader.gif problem How to capture client’s IP in PHP Gallery How to capture client’s IP in PHP How to Configure SMTP for office 365 in Easy WP SMTP Plugin – WordPress Gallery How to Configure SMTP for office 365 in Easy WP SMTP Plugin – WordPress