Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'kleo_new_excerpt_length' ) ) {
- function kleo_new_excerpt_length($length) {
- return 60;
- }
- add_filter('excerpt_length', 'kleo_new_excerpt_length');
- }
- if ( ! function_exists( 'kleo_excerpt' ) ) {
- function kleo_excerpt( $limit = 20, $words = true ) {
- $from_content = false;
- $excerpt_initial = get_the_excerpt();
- if( $excerpt_initial == '' ) {
- $excerpt_initial = get_the_content();
- $from_content = true;
- }
- $excerpt_length = apply_filters( 'excerpt_length', $limit );
- $excerpt_initial = preg_replace( '`\[[^\]]*\]`', '', $excerpt_initial );
- $excerpt_initial = strip_tags( $excerpt_initial );
- $excerpt_initial = mb_substr( $excerpt_initial, 0, $excerpt_length );
- /* If we got it from get_the_content -> apply length restriction */
- if ( $from_content ) {
- $excerpt_length = apply_filters( 'excerpt_length', $limit );
- $excerpt_initial = wp_trim_words( $excerpt_initial, $excerpt_length, '' );
- }
- if ( $words ) {
- $excerpt = explode( ' ', $excerpt_initial, $limit );
- if ( count( $excerpt ) >= $limit ) {
- array_pop( $excerpt );
- $excerpt = implode( " ", $excerpt ) . '...';
- } else {
- $excerpt = implode( " ", $excerpt ) . '';
- }
- } else {
- $excerpt = substr( $excerpt_initial, 0, $limit ) . ( strlen( $excerpt_initial ) > $limit ? '...' : '' );
- }
- return '<p>' . $excerpt . '</p>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement