- This topic has 7 replies, 2 voices, and was last updated 3 years, 5 months ago by
Ying.
-
AuthorPosts
-
February 5, 2023 at 9:37 am #2522315
Arp
The problem with using the excerpt is that it doesn’t have any html for embeds – and I’m trying to setup an archive with post formats (similar to Tumblr). I’m guessing there must be a snippet to limit the length of the post content in a Dynamic Content block?
February 5, 2023 at 11:42 am #2522419Ying
StaffCustomer SupportHi there,
This is not controlled by the theme, you can use a plugin for that:
https://www.wpbeginner.com/plugins/how-to-customize-wordpress-excerpts-no-coding-required/February 6, 2023 at 9:13 am #2523433Arp
Thanks Ying!
February 6, 2023 at 11:24 am #2523571Ying
StaffCustomer SupportNo Problem 🙂
February 7, 2023 at 4:35 pm #2525245Arp
I finally got around to reading the page and while it talks about customizing excerpts, it says nothing about enabling html in excerpts.
I need to either A) enable HTML in excerpts or B) limit the length of the content produced by the Dynamic Content block.
February 7, 2023 at 5:50 pm #2525295Ying
StaffCustomer SupportWrote this code, but not sure if it’s going to work well with GP dynamic content block, give it a try and let me know 🙂
I’ve set the length to 20 words, feel free to change the
20to your desired value.function limit_content_length_with_html( $content ) { if( is_archive() || is_home() ) { return force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( $content ), 20, '...' ) ) ); } return $content; } add_filter( 'the_content', 'limit_content_length_with_html' );February 8, 2023 at 9:43 am #2526225Arp
That worked! The only thing missing is the Read More button. Is that easy to add?
I also spent the last 2 hours trying to customize the function a bit to strip the tags for a particular category (or show an excerpt for that category), to no avail. Any suggestions for that?
February 8, 2023 at 5:38 pm #2526577Ying
StaffCustomer SupportI modified the snippet a bit, just need to replace the
1ofis_category('1')with your category ID which can be found in the URL of the category editor.function limit_content_length_with_html( $content ) { if( (is_archive() && ! is_category('1'))|| is_home() ) { $content = force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( $content ), 20, '...' ) ) ); $read_more_link = '<a href="' . get_permalink() . '">Read More</a>'; $content .= $read_more_link; } return $content; } add_filter( 'the_content', 'limit_content_length_with_html' ); -
AuthorPosts
- You must be logged in to reply to this topic.