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


Using the Image ID returns Title as Home

  • Hello everyone, Im stomped. I’m having a repeater and want to get Images, so far so easy. Now I just realised that every Image has the Title Home (the Images have completely different Titles and alts, is this a Syntax Error or should I rather switch to Array (I loved to have the Srcset though). Appreciate every help! Here is the Code I use.

                        if( have_rows('kunden') ):
                            while( have_rows('kunden') ) : the_row();  
                                $image = get_sub_field('bild');
                                $size = 'thumbnail';
                                if( $image ) {
                                  echo "<div class='medium-3 columns'>";
                                    echo wp_get_attachment_image( $image, $size );
                                    echo "</div>";
                        else :
  • What is your bild subfield returning? Are you able to share the output of the code? Are you referring to the title attribute of the image?

  • It returns the image with srcset and title=”home”. And yes the Title Attribute. Alt attribute is working, but title is a must for my client.

    <img width="400" height="400" src="***/wp-content/uploads/General-Motors.jpg" class="attachment-thumbnail size-thumbnail" alt="General Motors" loading="lazy" srcset="***/wp-content/uploads/General-Motors.jpg 400w, ***/wp-content/uploads/General-Motors-300x300.jpg 300w" sizes="(max-width: 639px) 98vw, (max-width: 1199px) 64vw, 400px" title="Home">

    I censored the URL it’s https:// if that makes any difference (which I guess it doesn’t)

  • 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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.