Previously at work, we had some issues in our CMS where some content editors would quickly create a post without a title, save the draft or publish, then add a title later. This caused a few issues in our headless service for select post types key to our business model. Without going into too much detail, I needed a way to restrict publishing & saving draft posts (of any type) without a title. A quick internet search brought me to some decent responses on Stack Overflow, and one good one on Kellen Mace‘s site.
Kellens article was from 2015, so I thought I would update it for current 2022 standard.
First we need to enqueue our javascript file by adding the code below to your themes functions.php file or use a functionality plugin (my preference).
Next, create a new javascript file. In this case I named it post-requirements.js
: