Skip to content

Instantly share code, notes, and snippets.

@WebEndevSnippets
Created January 19, 2013 14:03
Show Gist options
  • Save WebEndevSnippets/4572818 to your computer and use it in GitHub Desktop.
Save WebEndevSnippets/4572818 to your computer and use it in GitHub Desktop.
WordPress: Filter the_content on Blog Template
add_action( 'get_header', 'shireman_template_check' );
/**
* Filter the_content on Blog Page Template
*
*/
function shireman_template_check() {
if ( is_page_template( 'page_blog.php' ) )
add_filter( 'the_content', 'shireman_filter_blog_content' );
}
function shireman_filter_blog_content( $content ) {
$length = 500;
if(strlen($content)<$length+10) return $content; //don't cut if too short
$break_pos = strpos($content, ' ', $length); //find next space after desired length
$visible = substr($content, 0, $break_pos);
return balanceTags($visible) . '&nbsp;<a class="more-link" href="' . get_permalink() . '">[more&#x2026;]</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment