Appreciate the reply. Here’s the code we were given for use in the child theme functions.php to populate the alt tag that’s no longer working when using optimole. Appreciate any suggestions to customize for use with optimole.
/* Fetch image alt text from media library */
function get_image_alt_text($image_url) {
if ( ! $image_url )
return '';
if ( '/' === $image_url[0] )
$post_id = attachment_url_to_postid(home_url() . $image_url);
else
$post_id = attachment_url_to_postid($image_url);
$alt_text = get_post_meta($post_id, '_wp_attachment_image_alt', true);
if ( '' === $alt_text )
$alt_text = get_the_title($post_id);
return $alt_text;
}
/* Update image alt text in module properties */
function update_module_alt_text( $attrs, $unprocessed_attrs, $slug ) {
if ( ( $slug === 'et_pb_image' || $slug === 'et_pb_fullwidth_image' ) && '' === $attrs['alt'] )
$attrs['alt'] = get_image_alt_text($attrs['src']);
elseif ( $slug === 'et_pb_blurb' && 'off' === $attrs['use_icon'] && '' === $attrs['alt'] )
$attrs['alt'] = get_image_alt_text($attrs['image']);
elseif ( $slug === 'et_pb_slide' && '' !== $attrs['image'] && '' === $attrs['image_alt'] )
$attrs['image_alt'] = get_image_alt_text($attrs['image']);
elseif ( $slug === 'et_pb_fullwidth_header' ) {
if ( '' !== $attrs['logo_image_url'] && '' === $attrs['logo_alt_text'] )
$attrs['logo_alt_text'] = get_image_alt_text($attrs['logo_image_url']);
if ( '' !== $attrs['header_image_url'] && '' === $attrs['image_alt_text'] )
$attrs['image_alt_text'] = get_image_alt_text($attrs['header_image_url']);
}
return $attrs;
}
/* Add Filter to Include Alt Text from Media Library */
add_filter( 'et_pb_module_shortcode_attributes', 'update_module_alt_text', 20, 3 );