Making Media Library “Alternative Text” Field 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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x