# Post Excerpt limit characters

**URL:** <https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169>\
**Category:** Pinegrow Theme Converter\
**Tags:** wordpress\
**Created:** [March 29, 2021, 11:24pm UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169 "2021-03-29T23:24:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruggeropaolobasile](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ruggeropaolobasile](https://forum.pinegrow.com/u/ruggeropaolobasile)\
**Post date:** [March 29, 2021, 11:24pm UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169/1 "2021-03-29T23:24:34Z")

</div>

Hi all

# Post Excerpt

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

---

<div class="post-metadata">

**Author:** ![RobM](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@RobM](https://forum.pinegrow.com/u/RobM)\
**Post date:** [March 30, 2021, 9:45am UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169/2 "2021-03-30T09:45:02Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![vincentba](https://avatars.discourse-cdn.com/v4/letter/v/90db22/32.png) [@vincentba](https://forum.pinegrow.com/u/vincentba)\
**Post date:** [March 30, 2021, 4:38pm UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169/3 "2021-03-30T16:38:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RobM](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@RobM](https://forum.pinegrow.com/u/RobM)\
**Post date:** [March 30, 2021, 5:58pm UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169/4 "2021-03-30T17:58:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/emmanuel/32/6294_2.png) [@Emmanuel](https://forum.pinegrow.com/u/Emmanuel)\
**Post date:** [March 31, 2021, 6:35am UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169/5 "2021-03-31T06:35:36Z")

</div>

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

> **[How-to add features and functionality to your WordPress theme by using code...](https://pinegrow.com/tutorials/how-to-add-features-and-functionality-to-your-wordpress-theme-by-using-code-snippets/)**
>
> At the core of any WordPress theme, there is a file named functions.php and themes created with Pinegrow or Pinegrow Theme Converter for WordPress are no exceptions.

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.

> **[Pinegrow Web Editor 5.97 – July 8, 2020 | Pinegrow Web Editor](https://pinegrow.com/release_notes/pinegrow-web-editor-5-97-july-8-2020/#wordpress-theme-builder)**
>
> Tailwind Visual Editor add-on – Drag & Drop with collapsed elements – Reorganized HTML element Library – Copy paste attributes – Combined Undo history and more.

---

<div class="post-metadata">

**Author:** ![red-rosefields](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/red-rosefields/32/5392_2.png) [@red-rosefields](https://forum.pinegrow.com/u/red-rosefields)\
**Post date:** [March 9, 2023, 12:30pm UTC](https://forum.pinegrow.com/t/post-excerpt-limit-characters/5169/6 "2023-03-09T12:30:41Z")

</div>

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

 ![Screenshot 2023-03-09 at 13.45.54](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/c/c8051f22480f4279b4c6281b03da0ddd8d71d9dc.png)
