Support » Plugin: Image Widget » Empty alt attribute on images

  • Resolved sgwatwp


    In each instance of the widget on my site, I have an image selected from my media library.
    That image has the title & alt fields filled in.
    In the widget itself, I have the “Alternate Text:” field filled in.
    My title fields in the widget are empty as are the caption fields.
    The widgets all have the “Link:” field filled in.

    When I load my site and check the source, the links <a> have title attributes with the alt text of the widgets/images but the images <img /> within the links <a> have alt attributes that look like this…

    <img alt="" class="attachment-0x0 aligncenter" style="" src="">

    Any idea why my images lack alt attributes but the surrounding links are getting the alt text as titles?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I just noticed this same issue.

    Looking at the code for the current version, the issue is on line 277 of image-widget.php. At that point, you are ignoring the alt attribute that’s been set in the widget, and setting it to the Title argument (which, in my case, is blank, since I don’t want a title appearing above my image).

    On line 249, you’re also setting the “title” attribute of links (if the widget is supposed to include a link) to the “alt” attribute, unless the alt attribute is empty.

    Line 249 should probably look more like:
    'title' => ( ! empty( $instance['title'] ) ) ? $instance['title'] : $instance['alt'],

    and line 277 should probably look like:
    $attr['alt'] = empty( $instance['alt'] ) ? $instance['title'] : $instance['alt'];


    Thanks Curtiss – I made these changes and they’re doing exactly what I wanted.

    I wonder why the title & alt attributes were switched around in the code.

    Having this same problem – this is marked as resolved I assume because the suggested solution of changing the plugin works, but as best I can tell the plugin is not fixed?

    i agree to paracleteweb in their post above. This item has not been resolved by the developer, just information to change the code by another coder. But when the Image Widget is updated by the developer, all custom code will disappear. The developer need to look at their coding and update it to fix the error.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Empty alt attribute on images’ is closed to new replies.