• Resolved rockitman

    (@rockitman)


    Dear author,

    I am not sure if this question has already been asked. WordPress support, does not allow searching among topics (as far as I am aware).

    I would like to change the Theme option > Blog > Max amount of words in excerpt to…

    Theme option > Blog > Max amount of characters in excerpt

    Is this possible?

    Thanks you very much.

    Best,

    Bart

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Bart. Here’s an answer to a post that provides a function you could use in a child theme functions.php file. To use it you’d also need to change:

    <?php the_excerpt(); ?>

    to

    <?php get_excerpt(); ?>

    in the following theme files depending on where you want to use it:
    content.php
    content-featured.php
    content-standard.php

    Thread Starter rockitman

    (@rockitman)

    Thank you. It worked pretty well!

    For everyone’s convenience, I have added the following to my child function.php:

    function get_excerpt($limit, $source = null){
    
        if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt()));
        $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
        $excerpt = strip_shortcodes($excerpt);
        $excerpt = strip_tags($excerpt);
        $excerpt = substr($excerpt, 0, $limit);
        $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
        $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
        $excerpt = $excerpt.'... <a href="'.get_permalink($post->ID).'"><i class="fa fa-sort-down"></i></a>';
        return $excerpt;
    }

    And in my content-featured.php I have adjusted the following:

    <?php the_excerpt(); ?>

    And changed it to:

    <?php echo get_excerpt(40); ?>

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Max-Characters in excerpt’ is closed to new replies.