-
AuthorPosts
-
November 19, 2021 at 8:56 am #1329632
I just added some magazine elements to a page for my client and they noticed the line-breaks they’re using in their excerpts — which are showing as line-breaks in their blog element listings on other pages — are not showing in the magazine elements. Any way I can get those excerpts to show in the magazine elements too? Here’s an example excerpt: https://prnt.sc/2014g8v — and you can see the line-breaks showing in this blog element: 1st post “Never Mercy” on https://newissue.wpengine.com/weekly-content/amuse-bouche/ — and not showing (for the same post) in this magazine element: see Amuse-Bouche featured post “Never Mercy” on https://newissue.wpengine.com/weekly-content/
Thanks and lmk if you have any questions!
November 19, 2021 at 1:28 pm #1329677Hey sky19er,
Thank you for the inquiry.
It might be due do this line (1297) in the enfold/config-templatebuilder/avia-shortcodes/magazine/magazine.php file, which truncates and removes any line breaks in a text or string.
$excerpt = ! empty( $entry->post_excerpt ) ? $entry->post_excerpt : avia_backend_truncate( $entry->post_content, apply_filters( 'avf_magazine_excerpt_length', 60 ), apply_filters( 'avf_magazine_excerpt_delimiter', ' ' ), '…', true, '' );
Unfortunately, it is not possible to modify the excerpt via filter or hook, so editing the magazine.php file might be necessary in this case.
Or you could define the excerpt of the posts manually instead of relying on the default post content, which is where the summary is taken.
Best regards,
IsmaelNovember 19, 2021 at 10:01 pm #1329744Thanks, Ismael, but to be clear re your last sentence, the client is defining the excerpts manually. And again, the line breaks aren’t being stripped out in the Blog Posts element (at least not in the Single author, small preview pic layout); only in the Magazine element.
November 22, 2021 at 5:20 am #1329882Hi,
Thank you for the update.
Looks like WordPress automatically strips html tags including line breaks before saving the excerpt and the content. You may need to add the following snippet in the functions.php file to allow certain tags in the excerpt.
function wpse_allowedtags() { return '<script>,<style>,,<em>,<i>,<ul>,<ol>,<li>,<a>,,<img>,<video>,<audio>'; } if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) : function wpse_custom_wp_trim_excerpt($wpse_excerpt) { $raw_excerpt = $wpse_excerpt; if ( '' == $wpse_excerpt ) { $wpse_excerpt = get_the_content(''); $wpse_excerpt = strip_shortcodes( $wpse_excerpt ); $wpse_excerpt = apply_filters('the_content', $wpse_excerpt); $wpse_excerpt = str_replace(']]>', ']]>', $wpse_excerpt); $wpse_excerpt = strip_tags($wpse_excerpt, wpse_allowedtags()); /*IF you need to allow just certain tags. Delete if all tags are allowed */ //Set the excerpt word count and only break after sentence is complete. $excerpt_word_count = 75; $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); $tokens = array(); $excerptOutput = ''; $count = 0; // Divide the string into tokens; HTML tags, or words, followed by any whitespace preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens); foreach ($tokens[0] as $token) { if ($count >= $excerpt_length && preg_match('/[\,\;\?\.\!]\s*$/uS', $token)) { // Limit reached, continue until , ; ? . or ! occur at the end $excerptOutput .= trim($token); break; } // Add words to complete sentence $count++; // Append what's left of the token $excerptOutput .= $token; } $wpse_excerpt = trim(force_balance_tags($excerptOutput)); $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf(__( 'Read more about: %s »', 'wpse' ), get_the_title()) . '</a>'; $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */ return $wpse_excerpt; } return apply_filters('wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt); } endif; remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
Best regards,
IsmaelNovember 28, 2021 at 8:48 am #1330725Thanks, Ismael, but I think we’re still misunderstanding each other. Simple line-breaks in the custom excerpts (like this https://prnt.sc/20xtwsa ) are working fine in the Blog element (in every option with excerpts except the grid layout — see first post on https://newissue.wpengine.com/weekly-content/amuse-bouche/ for example) — they’re just not working in the Magazine element (see https://prnt.sc/20xty1r ). Nevertheless, I did try adding your snippet, and I added a br to the list of allowed tags at the top, but it didn’t seem to work. Any other ideas? Thanks again!
November 29, 2021 at 4:16 am #1330770Hi,
Thank you for the update.
It actually works when you manually add the br tag after every line in the excerpt. Please check the screenshot below.
Screenshot: https://imgur.com/a/c6ouGW3
Best regards,
IsmaelNovember 29, 2021 at 10:01 am #1330814Right, but it works without even adding the br tags in the blog element and, since this client has a bunch of layperson contributors adding posts, I was hoping we could get it to work without having to tell them to add code in the excerpts — know what I mean?
November 30, 2021 at 9:16 am #1330950Hi,
Right, but it works without even adding the br tags in the blog element
The blog element actually displays the post content, not the excerpt. And it looks like WordPress do not automatically add paragraph tags or create new lines for the excerpt, so if you want the magazine to work the same as the blog element, you have to remove the post excerpt and modify the magazine.php file, around line 1297 look for this code.
$excerpt = ! empty( $entry->post_excerpt ) ? $entry->post_excerpt : avia_backend_truncate( $entry->post_content, apply_filters( 'avf_magazine_excerpt_length', 60 ), apply_filters( 'avf_magazine_excerpt_delimiter', ' ' ), '…', true, '' );
Replace it with:
$excerpt = avia_backend_truncate( $entry->post_content, apply_filters( 'avf_magazine_excerpt_length', 60 ), apply_filters( 'avf_magazine_excerpt_delimiter', ' ' ), '…', false, '' );
Just make sure that you are not using any shortcodes in any of your posts because what we did with the modification is disable the function that strips the shortcodes and html tags.
Best regards,
IsmaelNovember 30, 2021 at 9:32 am #1330955Hmm, but the Blog Posts element I’m using seems to be pulling from the Excerpt field. For example, I just added a few dots to the end of the first line in the Excerpt field for Never Mercy (see https://prnt.sc/212tca0 ) and those dots show on https://newissue.wpengine.com/weekly-content/amuse-bouche/ . Am I misunderstanding?
December 1, 2021 at 2:06 pm #1331160Hi,
Did you manually add the br tags in the excerpt? This is the actual rendered html in the page containing the blog posts.
Don’t let go… < br > Those words. < br > Let go of what? < br > I cast her a look. < br > Her feet < br >
NOTE: I added spaces to the br tags because the forum automatically strips them.
Can we login to the site?
Best regards,
IsmaelDecember 1, 2021 at 9:45 pm #1331228No, that’s what I’m saying: apparently, with the Blog Posts element, the contributors can just use carriage returns in the Excerpt field, like this: https://prnt.sc/212tca0 — that’s a screenshot of the current Excerpt field for that post.
December 2, 2021 at 4:25 pm #1331331Hi,
Thank you for the screenshot.
We have found the difference between the blog posts element and the magazine. In the blog posts element, the content or the excerpt runs through the “the_content” filter, so the required formatting including line breaks get applied before actually returning the text. This is not true for the magazine element.
To change that we have to modify the same line (1297) of code above.
$excerpt = ! empty( $entry->post_excerpt ) ? $entry->post_excerpt : avia_backend_truncate( $entry->post_content, apply_filters( 'avf_magazine_excerpt_length', 60 ), apply_filters( 'avf_magazine_excerpt_delimiter', ' ' ), '…', true, '' );
And add this code below.
$excerpt = str_replace( ']]>', ']]>', apply_filters( 'the_content', $excerpt ) );
This is the result after doing the modification above. (see private field)
Best regards,
IsmaelDecember 4, 2021 at 9:23 am #1331527Thanks for your diligence as always, Ismael! I assume there’s no filter for the child theme. Do you think this will be included in a future theme update, or do they actually want to keep the Magazine element working differently like that for some reason?
December 4, 2021 at 1:40 pm #1331537Hi,
I added
$excerpt = str_replace( ']]>', ']]>', apply_filters( 'the_content', $excerpt ) );
for the next release 4.8.7.2.
Think, it makes sense.
Also added filter avf_magazine_skip_excerpt_content_filter to skip.
Best regards,
GünterDecember 24, 2021 at 8:23 am #1333930Beautiful — thanks, Günter!
-
AuthorPosts
- The topic ‘excerpt line breaks not showing in magazine element’ is closed to new replies.