Skip to content

Instantly share code, notes, and snippets.

@aprea
Created June 24, 2014 05:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprea/82b5cf043ade04f55463 to your computer and use it in GitHub Desktop.
Save aprea/82b5cf043ade04f55463 to your computer and use it in GitHub Desktop.
Only add the "add more" link when required
<?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