WordPress.org

Ready to get started?Download WordPress

Forums

gallery shortcode doesn't add alt text pages fail validation (21 posts)

  1. mccormicky
    Member
    Posted 6 years ago #

    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.

  2. Monika
    Member
    Posted 6 years ago #

    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

  3. fob
    Member
    Posted 6 years ago #

    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

  4. mccormicky
    Member
    Posted 6 years ago #

    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.

  5. fob
    Member
    Posted 6 years ago #

    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... ;-)

  6. mccormicky
    Member
    Posted 6 years ago #

    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.

  7. fob
    Member
    Posted 6 years ago #

    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

  8. fob
    Member
    Posted 6 years ago #

    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.

  9. fob
    Member
    Posted 6 years ago #

    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. ;-)

  10. mccormicky
    Member
    Posted 6 years ago #

    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.

  11. Monika
    Member
    Posted 6 years ago #

    fob

    you made my day

    I'll test and then write an article at home ;)

    thanks a lot

  12. fob
    Member
    Posted 6 years ago #

    Thanks very much! ;-)

  13. Justin Tadlock
    Member
    Posted 6 years ago #

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

  14. fob
    Member
    Posted 6 years ago #

    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.

  15. minute44
    Member
    Posted 6 years ago #

    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.

  16. Justin Tadlock
    Member
    Posted 6 years ago #

    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.

  17. minute44
    Member
    Posted 6 years ago #

    Sweet, it's the only thing stopping me using the feature at present. Plugins can cure the symptoms but it's not an ideal way of dealing with it.

  18. Justin Tadlock
    Member
    Posted 6 years ago #

    There are some other issues such as the gallery code not actually getting the thumbnail or medium-sized image, even if you specify in the shortcode to get it. I think it only pulls in the large version of the image and resizes it, which could make page load times pretty rough if you have a large gallery. I, of course, changed that in my plugin.

    OK, I'm about to quit boasting and go help some people.

  19. minute44
    Member
    Posted 6 years ago #

    Do you know anything about 2.5.1 possibly having the ability to not rely on inline styles?

  20. Justin Tadlock
    Member
    Posted 6 years ago #

    I'm not sure how they're going to do it. I haven't been hanging around trac lately. It'd be tough to figure out. Inline styles shouldn't be the way to go because that will hinder the user's ability to style the gallery. However, if they don't use them, they'd have to put a stylesheet in the header of everyone's blog or force theme author's to style the gallery.

    It's a tough thing to make work perfectly out of the box because it has to rely on some type of styling.

  21. minute44
    Member
    Posted 6 years ago #

    Answer:

    Tick box saying "I'll use an external stylesheet to style my galleries" and then a box where you type the url of your stylesheet.

    Done.

Topic Closed

This topic has been closed to new replies.

About this Topic