Show Alert Box when your Title box Empty on WordPress

When you write any WordPress post and you clicked on Publish button, Then post posted by default title name or post id. But you want to show alert box when click on publish button when title box is empty.

How to do

  • Open functions.php file first.
  • Then paste given code –
function add_title_validation() {
?>
<script>
jQuery(document).ready(function() {
jQuery('#publish').click(function() {
if(jQuery('#title').val().length === 0) {
alert('Enter a title first');
return false;
}
});
});
</script>
<?php
}
add_action('admin_head', 'add_title_validation');
  • Then click to SAVE button.

When you use this code on your WordPress theme, Then you show alert box when title box is empty.