Home / functions.php / Set maximum post title length
  • Set maximum post title length

    Adding this PHP code to the functions.php of your wordpress theme will set a maximum number of words that can be displayed within your post title.

    wordpress snippet : PHP

    function maxWord($title){
        global $post;
        $title = $post->post_title;
        if (str_word_count($title) >= 10 ) //set this to the maximum number of words
            wp_die( __('Error: your post title is over the maximum word count.') );
    add_action('publish_post', 'maxWord');

    ( WordPress codex functions, hooks, in this snippet. )

    publish_post, add_action, __, wp, wp_die,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks