Created
January 19, 2013 14:03
-
-
Save WebEndevSnippets/4572818 to your computer and use it in GitHub Desktop.
WordPress: Filter the_content on Blog Template
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
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) . ' <a class="more-link" href="' . get_permalink() . '">[more…]</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment