• Resolved rbarron

    (@rbarron)


    How do I get optimole to use the image alt text from the media library? The values are missing from the images hosted on optimole.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Vytis

    (@bvytis)

    Hi @rbarron,

    Thank you for using Optimole.

    Optimole does not change alt attributes in any way so if they are originally added to the images they will be served but if they are missing Optimole will not add them either.

    Please make sure that alt attributes exist with Optimole disabled and you should continue seeing them even after enabling Optimole.

    I hope it helps!

    Thread Starter rbarron

    (@rbarron)

    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 );
    Plugin Support Vytis

    (@bvytis)

    Hi @rbarron,

    Apologies for the delayed reply.

    We were checking with the development team about this but we require a bit more details to investigate and suggest a workaround in this specific situation.

    Could you please contact us via the contact form here – https://optimole.com/#contact

    We will send our support plugin to access your dashboard, this should help us to come up with a solution or an alternative. Thanks!

    Thread Starter rbarron

    (@rbarron)

    Will do, thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Image Alt Tags’ is closed to new replies.