Skip to content

Instantly share code, notes, and snippets.

@MatRouault
Last active April 23, 2016 15:09
Show Gist options
  • Save MatRouault/b6e64939d76d9a00e53250d5482bb4b5 to your computer and use it in GitHub Desktop.
Save MatRouault/b6e64939d76d9a00e53250d5482bb4b5 to your computer and use it in GitHub Desktop.
Beans - Show Excerpt or Troncate Content if we're NOT on a singular post/page
<?php
// Do not include the opening php tag if it is already included in your file.
//* Show Excerpt or Troncate Posts Content
add_filter( 'the_content', 'sps_troncate_post_content' );
function sps_troncate_post_content( $content ){
if ( !is_singular() )
if ( has_excerpt() ) {
return '<p>' . get_the_excerpt() . '</p><p>' . beans_post_more_link() . '</p>';
}
else {
return '<p>' . wp_trim_words( wp_strip_all_tags( $content, true ), 40, '...' ) . '</p><p>' . beans_post_more_link() . '</p>';
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment