Making Media Library “Alternative Text” Field Required

I’ve managed to make it work of sorts…

The requirement is not checked in the Media Library upload /wp-admin/media-new.php, but instead in the Media Upload thickbox iframe /wp-admin/media-upload.php.

enter image description here


The following is the code that works in the thickbox and displays an alert box making mandatory filling the Alt text field.
IMO, it won’t be easy, but it can be adapted to work in the Upload New Media page (/wp-admin/media-new.php)…

add_action('admin_head-media-upload-popup','wpse_55240_required_alt_text');
function wpse_55240_required_alt_text()
{
    ?>
    <script language="javascript" type="text/javascript">
        jQuery(document).ready(function($) {
            $(".submit .savesend input").live("click", validateAltText);

            function validateAltText() {
                var value = $(this).parent().parent().parent().find(".image_alt input").val();

                if (value) 
                    return true;

                alert("Please fill the Alt text");
                return false;
            }

            $('.image_alt th label').each(function(i,e) {
                $('<span class="alignright"><abbr title="required" class="required">*</abbr></span>').prependTo(this);
            });

        });
    </script>
<?php
}

Leave a Comment