How to Set a Minimum Word Count for WordPress Posts

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

It will. Setting minimum word count for posts means the site will not publish anything with less than that number of words. So any post with more words than the minimum will be published.

Are you sure you don’t mean that you would like to set the word length of the post excerpt?

1 Like

Its still publishing when wordcount is 0
Are you sure you don’t mean that you would like to set the word length of the post excerpt?
YA

Then add the following code to your functions.php file (in this example, the word count is set to 20):

function wpdocs_custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );

Then in your loop where the post is called, instead of having the_content(), use the_excerpt().

U mean below instruction ive to add in single.php file & for what reson
Then in your loop where the post is called, instead of having the_content() , use the_excerpt() .

Sorry for taking so long to reply - I have been very busy this week.

Place the function in your functions.php file. Do you have access to your files through your dashboard code editor?

the_excerpt goes in the file where you want just part of the post to be displayed, instead of the_content in your post loop. I can’t tell you where that is because I don’t have access to your theme.

1 Like

This is theme https://wordpress.org/themes/hitmag/ U can download it and check fileheader.php (4.5 KB) index.php (1.7 KB) page.php (1.0 KB) single.php (1.5 KB)

I still have not been able to find

I would prefer not to download and open any of those files, because I don’t know how secure they are.

Can u download here https://wordpress.org/themes/hitmag/

If this is a theme that you did not code yourself, you should not touch the code at all, because when an update to the theme comes out, and you install it, it will overwrite all your changes. And you can’t ignore the update. Often it fixes security holes in the theme.

You should use a child theme to make your changes. Go to WordPress.org and do a search for Child Themes.

2 Likes

I already have child theme

This theme uses template parts. So look in the files that start with template - template-builder.php, template-builder-fullwidth.php, template-magazine.php.

1 Like

I searched template - template-builder.php, template-builder-fullwidth.php, template-magazine.php. but only place i found it is below


So did you replace it with the_excerpt()? Maybe I just don’t understand exactly what you are trying to accomplish.

You posted a screen capture of “Caution: This is a file in your current parent theme”

Please try changing it in your child theme file.

2 Likes