Skip to content

Instantly share code, notes, and snippets.

@AnnaCrumina
Created December 28, 2015 09:38
Show Gist options
  • Save AnnaCrumina/5a43dd745939001c9c4f to your computer and use it in GitHub Desktop.
Save AnnaCrumina/5a43dd745939001c9c4f to your computer and use it in GitHub Desktop.
Characters instead of words in Excerpt length option for Secondtouch
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