Last active
August 29, 2015 14:17
-
-
Save ogbaoghene/c812c792d63c84e28a81 to your computer and use it in GitHub Desktop.
WordPress Custom Functions Bible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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