Created
June 24, 2014 05:46
-
-
Save aprea/82b5cf043ade04f55463 to your computer and use it in GitHub Desktop.
Only add the "add more" link when required
This file contains hidden or 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
<?php | |
function ca_only_add_more_when_required( $default, $text, $options ) { | |
$text = strip_tags( $text ); | |
if ( 'words' === $options['length_type'] ) { | |
$excerpt_length = str_word_count( $text ); | |
} else { | |
$excerpt_length = strlen( $text ); | |
} | |
if ( $excerpt_length > $options['length'] ) return $default; | |
return true; | |
} | |
add_filter( 'advanced_excerpt_disable_add_more', 'ca_only_add_more_when_required', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment