This topic has 1 reply, 2 voices, and was last updated 6 years by Radu.

  • Author
  • #205639
     jrozsa
    Participant

    This seems like something that would have been added by now, but I do not see it.  It isn’t still a manual code change, is it?

    #205689
     Radu
    Moderator

    Hi,

    1.
    The limit can be changed by addind the next codes to /wp-content/themes/kleo-child/functions.php

    Replace 350 with your desired number or characters

    Code below:

    COPY CODE
    
    if ( ! function_exists( 'kleo_excerpt' ) ) {
        function kleo_excerpt( $limit = 50, $words = false ) {
            /*Force excerpt length*/
            $limit = 350;
            $from_content    = false;
            $excerpt_initial = get_the_excerpt();
    
            if ( $excerpt_initial == '' ) {
                $excerpt_initial = get_the_content();
                $from_content    = true;
            }
            $excerpt_initial = preg_replace( '<code>\[[^\]]*\]</code>', '', $excerpt_initial );
            $excerpt_initial = strip_tags( $excerpt_initial );
    
            /* 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>';
        }
    }
    
    function kleo_new_excerpt_length( $length ) {
        return 350;
    }
    
    

    Child theme needs to be installed and activated.

    Cheers
    R

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 2 posts - 1 through 2 (of 2 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?