Created
December 28, 2015 09:38
-
-
Save AnnaCrumina/5a43dd745939001c9c4f to your computer and use it in GitHub Desktop.
Characters instead of words in Excerpt length option for Secondtouch
This file contains hidden or 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
function content( $num, $no_more = false ) { | |
global $post; | |
$options = get_option( 'second-touch' ); | |
if ( $options['read_more_style'] == '0' ) { | |
$read_more_link = '<a href="' . get_permalink( $post->ID ) . '" class="link-read-more"> </a>'; | |
} else { | |
$read_more_link = '<a href="' . get_permalink( $post->ID ) . '"> ' . __( 'Read more', 'crum' ) . '</a>'; | |
} | |
if ( $no_more == true ) { | |
$read_more_link = ''; | |
} | |
$post_excerpt = get_post_field( 'post_excerpt', get_the_ID() ); | |
if ( isset( $post_excerpt ) && ! ( empty( $post_excerpt ) ) ) { | |
$post_content = $post_excerpt; | |
} else { | |
$post_content = strip_tags( get_post_field( 'post_content', get_the_ID() ) ); | |
} | |
$post_content = strip_shortcodes( $post_content ); | |
//$post_text = wp_trim_words( $post_content, $num ); | |
$post_text = mb_substr( $post_content, 0, $num ); | |
$content = wpautop( $post_text ) . $read_more_link; | |
echo $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment