How to Set a Minimum Word Count for WordPress Posts


How to Set a Minimum Word Count for WordPress Posts
Lance Watson

Hello
 
No need to globalize $post since it’s passed in 2nd argument.
You “$content” parameter is wrong, the 1st param is not the content but a post ID.
So i modified the code to change this, i used ‘dummy’ to understand we do not need it in you function.
 
function minWord( $postID_dummy, $post ) {
  $content = $post->post_content;
  if (str_word_count($content) < 100 ) //set this to the minimum number of words
    wp_die( __(‘Error: your post is below the minimum word count. It needs to be longer than 100 words.’) );
}
add_action( ‘publish_post’, ‘minWord’, 10, 2 );
 
Core : http://core.trac.wordpress.org/browser/trunk/wp-includes/post.php#L2980
 
See you !
 
Julio – WordPress Expert.

How to Set a Minimum Word Count for WordPress Posts
Monika Shields

I tried dis steps https://www.wpbeginner.com/wp-tutorials/how-to-set-a-minimum-word-count-for-wordpress-posts/ to Set a Minimum Word Count for WordPress Posts
but even if i Set a Minimum Words it triggers like dis https://share-ask.com/s/error which is perfect but insted of not publising dat post wich is lesser in wordcount it still publishes page

How to Set a Minimum Word Count for WordPress Posts
Bao Mount

Have you googled that question? I just did, and came up with quite a few articles that deal with that issue. For example:
https://trickspanda.com/set-minimum-word-count-wordpress-posts/
https://wpeden.com/tipsntuts/set-a-minimum-word-count-for-wordpress-posts/

Be the first to comment

Leave a Reply

Your email address will not be published.


*