Getting TinyMCE to respect empty alt attributes

This one took a little futzing around and digging through the TinyMCE forum to figure out, but it’s been nagging at me for a while. By default (or at least in the default configuration provided under the LG TinyMCE extension for ExpressionEngine), TinyMCE will remove the alt attribute if it is empty. Obviously, for accessibility and validation reasons, this is highly undesirable and needs correcting. Thankfully, the fix is pretty simple: add the following to your TinyMCE configuration options:

// fix empty alt attributes
extended_valid_elements : 'img[src|alt=|title|class|id|style|height|width]',
verify_html : true,
view raw gistfile1.js hosted with ❤ by GitHub

I choose to add these options right after declaring my cleanup/output options but before the remainder of the configuration. If you choose to tack these options on at the end, just remember to remove the trailing comma.

Like it? Share it

Share on LinkedIn

Share on Google Plus

View comments on this entry