Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save enqtran/9cd9c119d9b1dd3be509666a09323f9e to your computer and use it in GitHub Desktop.
Save enqtran/9cd9c119d9b1dd3be509666a09323f9e to your computer and use it in GitHub Desktop.
/**
* [force_post_title_init]
*/
function force_post_title_init() {
wp_enqueue_script('jquery');
}
function force_post_title() {
echo "<script>jQuery('#publish').click(function(){
var testervar = jQuery('[id^=titlediv]').find('#title');
if (testervar.val().length < 1)
{
jQuery('#title').css('border', '2px solid red');
setTimeout(jQuery('#ajax-loading').css('visibility', 'hidden'), 100);
alert('POST TITLE is required');
setTimeout(jQuery('#publish').removeClass('button-primary-disabled'), 100);
return false;
}
});</script>";
}
add_action('admin_init', 'force_post_title_init');
add_action('edit_form_advanced', 'force_post_title');
add_action('edit_page_form', 'force_post_title');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment