Skip to content

Instantly share code, notes, and snippets.

@ogbaoghene
Last active August 29, 2015 14:17
Show Gist options
  • Save ogbaoghene/c812c792d63c84e28a81 to your computer and use it in GitHub Desktop.
Save ogbaoghene/c812c792d63c84e28a81 to your computer and use it in GitHub Desktop.
WordPress Custom Functions Bible
/* Controlling excerpt length using filters */
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/* Limit content length */
function word_limit($string, $max_words){
$post_words = explode(' ', $string);
$count = count($post_words);
$post_words = implode(' ', array_slice($post_words, 0, $max_words));
if($count > $max_words):
return $post_words . '...';
else:
return $post_words;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment