WordPress: Publish Button Event Handler

013th Jul 2013Uncategorized, , ,

I’ve been working on a new project in WordPress, and I needed a way to do some validation with JavaScript when clicking the “Publish” button.

So, here’s the easy snippet:

jQuery(document).ready(function(){
  // When the "Publish" button is clicked.
  jQuery("#publish").click(function(event){
    // Check our condition.
    if(myBoolean){
      alert( "Message here telling why the post can't be submitted." );
      event.stopImmediatePropagation();
      return false;
    }
  });
});

No Comments Comments Feed

Add a Comment

Before you post, please prove you are sentient.

what is 2 in addition to 2?