How To Replace Default Alt Value In Image Module With The One You Can Set Under Attachment Settings - kary4/divituts GitHub Wiki

  1. Create a child theme or simply download it from here: https://github.com/kary4/divituts/wiki/divi-child-theme

  2. In the child theme folder create a new folder, for example includes folder.

  3. Now copy the divi/includes/builder/module/image.php file into the child-theme/includes/ folder.

  4. Rename the file to something else, for example: custom-image.php.

  5. Open up the custom-image.php file and replace this code (the first line):

class ET_Builder_Module_Image extends ET_Builder_Module

with:

class Custom_ET_Builder_Module_Image extends ET_Builder_Module

Next, remove this line at the very bottom: new ET_Builder_Module_Image;.

  1. Also, right after this line:
$parallax_image_background = $this->get_parallax_image_background();

add this one:

global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $src )); 
$alt_pw = get_post_meta( $attachment[0], '_wp_attachment_image_alt', true );

6.2. And replace this code line:

esc_attr( $alt ),

with:

esc_attr( $alt_pw ),
  1. Next open up functions.php file in your child theme folder and add the following code at the very bottom:
function custom_image_setup() {
	get_template_part( 'includes/custom-image' );
	$custom_image = new Custom_ET_Builder_Module_Image();
	remove_shortcode( 'et_pb_image' );
	add_shortcode( 'et_pb_image', array( $custom_image, '_shortcode_callback' ) );
}
add_action( 'et_builder_ready', 'custom_image_setup' )