I cannot make the title field (of the post) required before to publish a post with Gutenberg interface.
I try with this function but that don't work. Those functions are not adapted for Gutenberg I think.
function force_post_title_init() {
wp_enqueue_script('jquery');
}
function force_post_title() {
echo "<script type='text/javascript'>";
echo "
jQuery('.editor-post-publish-button__button').click(function(){
var testervar = jQuery('.editor-post-title').find('.editor-post-title__input');
if (testervar.val().length < 1) {
jQuery('.editor-post-title').css('border', '1px solid red');
$( '.editor-post-title' ).after('<label>Post title is required</label>'); // Make it red according your requirement
return false;
}
});
";
echo "</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');
Do you have any idea please ?