Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created October 17, 2019 21:33
Show Gist options
  • Save lgedeon/9b42731e8bccbaca1e49c7e93eb37159 to your computer and use it in GitHub Desktop.
Save lgedeon/9b42731e8bccbaca1e49c7e93eb37159 to your computer and use it in GitHub Desktop.
Stop publish if too many/few words.
$(document).on('submit', '#post', function() {
const coreWordCounter = new window.wp.utils.WordCounter();
const $mtSeoTitle = $( '#mt_seo_title' );
const mtWordCount = coreWordCounter.count( $mtSeoTitle.val() );
if ( 18 < mtWordCount ) {
alert( 'SEO Error: The title in your SEO Pack cannot exceed 18 words when included in Google News. Please try again.' );
$( this ).find( 'input[type="submit"]' ).removeClass( 'disabled' )
.end().find( '.spinner' ).hide();
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment