Home Forums Front-end Issues Using the Image ID returns Title as Home Reply To: Using the Image ID returns Title as Home

  • Since my client is pressuring me a lot, I ditched srcset temporary to get a proper title.

          if( have_rows('kunden') ):
            while( have_rows('kunden') ) : the_row(); ?> 
                   $image = get_sub_field('bild');
                   $size = 'thumbnail';
                   $thumb = $image['sizes'][ $size ];
                   if( !empty( $image ) ): ?>
                     <div class="medium-3 columns">
                       <img />" alt="<?php echo esc_attr($image['alt']); ?>" title="<?php echo esc_attr($image['title']); ?>" />
                    <?php endif; ?>
            <?php endwhile;
                  else :

    Since wp_get_attachment doesn’t return the right img title by default, I tried workarounds. The ones I found where messing up the site or didn’t work at all and my own didn’t work as well.

    After rethinking the title attribute, I just decided to get rid of it.


    add_filter('wp_get_attachment_link', 'opt_remove_title_attr');
    add_filter('wp_get_attachment_image', 'opt_remove_title_attr');
    add_filter('wp_nav_menu', 'opt_remove_title_attr');
    add_filter('wp_page_menu', 'opt_remove_title_attr');
    add_filter('wp_list_categories', 'opt_remove_title_attr');
    add_filter('wp_list_pages', 'opt_remove_title_attr');
    add_filter('wp_get_archives', 'opt_remove_title_attr');
    add_filter('get_archives_link', 'opt_remove_title_attr');
    add_filter('post_thumbnail_html', 'opt_remove_title_attr');
    function opt_remove_title_attr($return){
        return preg_replace('<code>title=&quot;(.+)&quot;</code>', '',$return);

    To get rid of any title and used the code I used before, now it works like a charm, with no title attribute and srcset.

    Maybe this helps someone having the same issue.