WordPress.org

Support

Support » How-To and Troubleshooting » gallery shortcode doesn’t add alt text pages fail validation

gallery shortcode doesn’t add alt text pages fail validation

  • I noticed this problem and tested it several different ways,adding captions (the alternative text field) or not, using the edit option to insert alt text or leaving it blank and finally trying just one image.A single image will get alt text or just alt=””,depending on whether or not you leave it blank.But all images within the gallery shortcode will not.I looked at wp-includes/media.php and couldn’t find alt being mentioned anywhere.
    But as a final test I checked one of matt’s new gallery posts.
    His pictures have alt=””. This gallery post doesn’t validate but for other reasons. Also his pages don’t get the gallery.css inserted into the post or page or where ever there’s a gallery. Mine do.
    All my posts or pages with a gallery in them fail validation miserably.
    You aren’t supposed to have style tags where the gallery puts inserts them. The detailed list isn’t right either. I get this message:
    document type does not allow element “dl” here; missing one of “object”, “applet”, “map”, “iframe”, “button”, “ins”, “del” start-tag.

    One final complaint:if I click on an archived post with a gallery in it it prints the css for the gallery as the excerpt of the post.
    This doesn’t happen on matt’s site. Which makes me think that the code we got and the code he uses are 2 different things.

Viewing 15 replies - 1 through 15 (of 20 total)
  • yes, I have to realize the same things as you ,

    but no answers – no reactions ๐Ÿ™

    http://wordpress.org/support/topic/168098?replies=1

    regards

    Monika

    Hi. I have had the same problem and wrote a quick solution (plugin) to solve it:

    Please feel free to download my WordPress 2.5 Gallery Validation Plugin to get rid of the funny codes. You can change the plugin as well as the attached CSS if you like. It will override (filter) the funny shortcode of your media.php as long as needed.

    Additionally you might want to change the alt things within your media.php:

    Line 99 (use this):
    $html = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" '.$hwstring.'class="align'.attribute_escape($align).' size-'.attribute_escape($size).' wp-image-'.$id.'" />';

    line 327 (modify like this):
    $html = '<img src="'.attribute_escape($src).'" alt="" '.$hwstring.'class="attachment-'.attribute_escape($size).'" />';

    Unfortunatelly I couldnยดt load title or alt attributes to the second one. May be someone else knows the trick?

    The plugin and these two changes will make your theme valid. You can see this solution in action here. But don`t talk about it. This is a test domain, valid but not ready for official use. ๐Ÿ˜‰

    Tip: The Gallery Validation Plugin comes with two files. You could make use of the plugin code within your functions.php (theme folder) and put the css stuff in your own stylesheet as well. There should be no reason to do it – but if you want, you can.

    Best regards
    Oliver

    This looks like just the thing-as a designer I can’t have invalid pages on my portfolio site, esp. when I go on and on about the importance of valid xhtml. Thanks for coming up with something to correct it.

    You`re welcome. I also hate invalid pages. But people making use of a valid system normally do not need very much time to fill their system with lots of invalid codes. Shit happens… ๐Ÿ˜‰

    Your plugin got rid of the style tags and the incorrect detailed list which is great, but I still have an error for a closed p tag that is not open. This is just the usual wp editor stuff I’m sure.

    Thanks for your information. That`s funny. ๐Ÿ˜‰

    I have tried to figure out where the opening <p> tag would come from on my test domain. I could not find and delete it – so I addeded a closing </p> at the end of the code.

    You can delete the closing </p> within the plugin.
    Whatever you change there will override the defaults.

    Find this line at the end of the plugin code:
    $output .= "<br class='clear' /></p></div>";

    and change it like this:
    $output .= "<br class='clear' /></div>";

    So my <p> must have been written into the database while saving the gallery post. Will try to fix that today.

    Thanks and best regards
    Oliver

    I would love to know where exactly you get the p tag error from.
    Is it behind the clear tag or somewhere else?

    I checked my database: no <p> tag found.
    I checked if it could be an editor problem
    – seems not to be the case.
    I stripped the content output – <p> not found.
    I double checked including a few <p> and </p>
    into the output to strip it with an additional
    function – everything deleted but not the <p>
    which is automatically set directly behind
    the gallery output (in front of the clear tag).
    I double checked my templates: everything valid.

    No idea why I have to put the </p> into the plugin.

    Because of that I will have to leave it like it is
    until anybody has an idea why the gallery inserts
    the <p> where nobody wants to have it.

    Another thing I`ve seen:
    I forgot to put my .clear class into the stylesheet.

    I always use a clear class so that people might be
    able to fix line-height and other things the IE
    doesn`t like. May be you want to put it into your
    stylesheet (if you didn`t do that already) so that
    the floating stops behind the gallery pics.

    Okay. I found the problem!

    WordPress has a function included called “wpautop”. This function still puts <p> tags wherever it likes and where you definitely do not like to see them.

    I will kill this function for galleries now. The Gallery Validation Plugin Update will be available within the next five minutes. ๐Ÿ˜‰

    I thought it was wpautop and there is a plugin to disable it but I used it for another site and it got rid of stuff I wanted to keep–made extra work in other words.
    I use a clear class too to stop the floats.
    Thanks for your research and work, this is great.

    fob

    you made my day

    I’ll test and then write an article at home ๐Ÿ˜‰

    thanks a lot

    Thanks very much! ๐Ÿ˜‰

    Justin Tadlock

    @greenshady

    WordPress God

    I also put together a plugin to handle this, which comes with Lightbox, Slimbox, and Thickbox support:
    Cleaner gallery plugin.

    Pretty cool. ๐Ÿ˜‰

    I am a search engine optimizer. That is why I need the single pages for each photo. Still activated “Shutter Reloaded” for additional effects on single pics. If the plugin is not necessary anymore it could be deactivated without loosing lightbox or other effects that come from Shutter out of the box.

    A plugin that makes the gallery shortcode valid is very good and hats off to whoever wrote it but I have to say I was super disappointed when I found out how poor the code was in the standard wordpress release.

    WordPress’ motto is “code is poetry” but this is poetry without meter or rhyme… it, in a word, sucks.

    2.5.1+ better fix this glaring issue or I’ll be even more disappointed.

    Justin Tadlock

    @greenshady

    WordPress God

    On the link I posted in the comments, Matt said, “The XHTML for the gallery should be completely valid for the next release.” So, I’m hoping that it’s 2.5.1.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘gallery shortcode doesn’t add alt text pages fail validation’ is closed to new replies.
Skip to toolbar