Last active
December 16, 2015 18:50
-
-
Save mcsf/5481130 to your computer and use it in GitHub Desktop.
[WordPress] Displays up to $length characters of the contents of the current post, taking care not to split words.
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
<?php | |
function mcsf_the_content( $length ) { | |
$content = get_the_content(); | |
$content = apply_filters( 'the_content', $content ); | |
$content = wp_filter_nohtml_kses( $content ); | |
$extra = substr( $content, $length, $length + 20 ); | |
$content = substr( $content, 0, $length ); | |
$matches = array(); | |
echo $content; | |
if ( preg_match( '/^( *)([^ ]+)/', $extra, $matches ) ) | |
echo $matches[1] . $matches[2] . esc_html( ' […]' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment