Saturday, April 23, 2011

Set a maximum word count on post title

Set a maximum word count on wordpress post titles

 If you want to be able to set a maximum word count of post titles so you dont have to think titles that are too long, the following code is help you to overcome that. Here I’ll show you how you can easily set a maximum word count on post titles.


 To apply this hack on wordpress post title , just paste the following ode in your functions.php file:

 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');

So with this code you can set a maximum word count on post title

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off