Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking to make the "Alternative Text" field required in the Media Library, just like the "Title" field above it.

Screenshot: enter image description here

share|improve this question
    
The only features of that required field are the asterisk and being automatically filled with the filename if left empty... –  brasofilo Jun 14 '12 at 20:21
    
Perhaps I should clarify, even more. I'd like the "Alternative Text" field to be mandatory when uploading an image to the Media Library. –  AlecRust Jun 15 '12 at 8:58

1 Answer 1

up vote 1 down vote accepted

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
}
share|improve this answer
    
Thanks a lot for that! Seems pretty hacky being client-side but if it's the same way the "Title" field is made required I guess that's the best implementation for now. You say the above code can be "adapted" to work, but it seems to do exactly what I need out of the box. Just checking there are no further modifications? –  AlecRust Jul 2 '12 at 11:17
    
@alecrust : I've rephrased my answer to make it clear what's working and where. –  brasofilo Jul 2 '12 at 11:35
    
Many thanks, got it working! –  AlecRust Jul 6 '12 at 10:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.