Image Widget
[resolved] Empty alt attribute on images (5 posts)

  1. sgwatwp
    Posted 2 years ago #

    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="http://www.mysite.com/wp-content/uploads/2013/01/image.png">

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


  2. Curtiss Grymala
    Posted 2 years ago #

    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'];


  3. sgwatwp
    Posted 2 years ago #

    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.

  4. paracleteweb
    Posted 2 years ago #

    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?

  5. bullseyedesigns
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Image Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic