Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:23:23+00:00 2026-06-06T09:23:23+00:00

I’m injecting some jQuery to make the Alt Text field required in WordPress upload

  • 0

I’m injecting some jQuery to make the Alt Text field required in WordPress upload thick box.

It intercepts the Insert into Post button click and checks if the field has been filled or not.

It works ok for the Gallery and Media Library tabs, but the From Computer tab needs a needs a “listener” when an upload finishes to alter the behavior of the Insert into Post button.

enter image description here



I was trying with setInterval, but don’t know how to kill or recreate it, but maybe someone is aware if a listener exists, or even how to make this code work because I suspect my logic here is fuzzy…

Here’s the code, commented.

add_action('admin_head-media-upload-popup','so_11149675_required_alt_text');

function so_11149675_required_alt_text()
{
    // Detect current tab ("From Computer" == "type")
    $tab = isset($_GET['tab']) ? $_GET['tab'] : "type";

    // ( 'From Computer' or ( 'Gallery' and 'Library' ) )
    $jquery = ('type' == $tab) ? 'var refreshUpload = setInterval(function(){$(".savesend input").each(checkAltTextPermanent);},500);' : '$(".savesend input").each(checkAltTextOnce);';

    echo <<<HTML
    <script language="javascript" type="text/javascript">
        // var refreshUpload; /* testing */

        // Function called by From Computer tab
        // should run only once -> when the upload table and fields are created
        function checkAltTextPermanent() {
            // Create the required asterisk symbol
            // setInterval creates a loop here
            jQuery('.image_alt th label').each(function(i,e) {
                jQuery('<span class="alignright"><abbr title="required" class="required">*</abbr></span>').prependTo(this);
            }); 

            // Alter button behavior
            // Another loop in the alert box
            jQuery(this).click(function(e) {
                // clearInterval(refreshUpload);
                var value = jQuery(this).parent().parent().parent().find('.image_alt input').val();

                if('' != value) 
                    return true;

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

        // Function called by Gallery and Library tabs
        function checkAltTextOnce() {
            jQuery(this).click(function(e) {
                var value = jQuery(this).parent().parent().parent().find('.image_alt input').val();

                if('' != value) 
                    return true;

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

        jQuery(document).ready(function($) {
            // Defined in PHP, calls checkAltTextOnce or checkAltTextPermanent
            {$jquery}

            // Used in Gallery and Libray tabs
            $('.image_alt th label').each(function(i,e) {
                $('<span class="alignright"><abbr title="required" class="required">*</abbr></span>').prependTo(this);
            });
        });
    </script>
HTML;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:23:24+00:00Added an answer on June 6, 2026 at 9:23 am

    Try this:

    jQuery(".savesend input").live("click", validateAltText);
    
    function validateAltText() {
        var value = $(".image_alt input").val();
    
        if (value) 
            return true;
    
        alert('Please fill the Alt text');
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.