Post Excerpt limit characters

Hi all

Post Excerpt

how is it possible to limit the number of characters to 300 in the post excerpt action?
Thanks in advance

Hi @ruggeropaolobasile,
I’m fairly sure you are going to have to filter your excerpt content with a custom function to filter your excerpt. Something like:

add_filter("get_the_excerpt", "custom_excerpt_length");
function custom_excerpt_length($excerpt="", $limit=300){
    $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 = '<p>'.$excerpt.'&hellip; <a href="'.$permalink.'">Read More</a></p>';
    return $excerpt;
}

Fair warning, this hasn’t been really tested. This will allow you to use the normal get_the_excerpt action within the Pinegrow Theme Converter.
Cheers,
Bob

Hi , im new in pinegrow, i have the same question. Where i can insert this code? is there an example ?
Thanks in advance

This code would go in your ‘functions.php’ file. There should be some good examples on the web - not directly a Pinegrow thing.
Bob

You can read more about how to add code snippets here:

Note: Since july 2020 and Pinegrow 5.97, the custom.php file is automatically added by Pinegrow so you just have to add your custom code inside the file.