Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Created May 22, 2014 17:40
Show Gist options
  • Save zackkatz/61f409ec1af7f7c3c771 to your computer and use it in GitHub Desktop.
Save zackkatz/61f409ec1af7f7c3c771 to your computer and use it in GitHub Desktop.
Require a title in the WordPress Edit Post screen
$('body').on( 'submit.edit-post', '#post', function () {
// If the title isn't set
if( $("#title").val().length === 0 ) {
// Show the alert
alert('A title is required.');
// Hide the spinner
$('#major-publishing-actions .spinner').hide();
// The buttons get "disabled" added to them on submit. Remove that class.
$('#major-publishing-actions').find( ':button, :submit, a.submitdelete, #post-preview' ).removeClass( 'disabled' );
// Focus on the title field.
$("#title").focus();
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment