Come impostare un numero minimo di parole per i post WordPress

Come impostare un numero minimo di parole per i post WordPress / Esercitazioni

Gestisci un blog con più autori? Quindi, probabilmente ti sei chiesto come impostare un conteggio minimo delle parole per i tuoi post in WordPress. In questo articolo, condivideremo con te uno snippet che ti consente di impostare un numero minimo di parole per i tuoi post WordPress. Se un utente tenta di pubblicare un post troppo piccolo, restituirà un errore indicando che il post non è abbastanza lungo.

Apri semplicemente i temi del tuo tema functions.php file e incolla il seguente codice:

funzione minWord ($ content) global $ 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');

Puoi cambiare il numero minimo di parole da 100 a quello che vuoi. Puoi anche personalizzare l'errore per renderlo utile.