Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #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!

    #1329677

    Hey 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,
    Ismael

    #1329744

    Thanks, 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.

    #1329882

    Hi,

    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() ) . '">' . '&nbsp;&raquo;&nbsp;' . sprintf(__( 'Read more about: %s &nbsp;&raquo;', '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,
    Ismael

    #1330725

    Thanks, 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!

    #1330770

    Hi,

    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,
    Ismael

    #1330814

    Right, 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?

    #1330950

    Hi,

    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,
    Ismael

    #1330955

    Hmm, 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?

    #1331160

    Hi,

    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,
    Ismael

    #1331228

    No, 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.

    #1331331

    Hi,

    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,
    Ismael

    #1331527

    Thanks 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?

    #1331537

    Hi,

    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ünter

    #1333930

    Beautiful — thanks, Günter!

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘excerpt line breaks not showing in magazine element’ is closed to new replies.