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 all
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.'… <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.
Perhaps a useful feature could be adding a “Limit Characters” option under the “Post Excerpt Smart Actions” section. This seems like a natural extension of the current “Excerpt” option. However, it’s possible that incorporating this functionality into PG (whatever that may be) could be challenging. If it is feasible, then it would make sense to implement this option.
Or… you just could ask Mr. ChatGPT