Viewing 23 posts - 1 through 23 (of 23 total)
  • Author
    Posts
  • #1335432

    Hi Guys,
    How can I adjust the excerpt length in enfold.
    I looked for this code in your artilce:
    https://kriesi.at/support/topic/blog-post-excerpts-2/?login_error#post-169503
    but could not find the exact match?
    $prepare_excerpt = !empty($entry->post_excerpt) ? $entry->post_excerpt : avia_backend_truncate($entry->post_content, apply_filters( ‘avf_postgrid_excerpt_length’ , 60) , apply_filters( ‘avf_postgrid_excerpt_delimiter’ , ” “), “…”, true, ”);

    Where could I find the right code to change or can I do this more simply in Enfold itself?

    Thanks for your anticipated help:)
    Kevin.

    #1335434

    Hey Kevin,

    Thanks for contacting us!

    Which element are you using? If you are using grid style on Blog Posts element, please add following code to bottom of Functions.php file of your child theme – https://kriesi.at/documentation/enfold/child-theme/

    add_filter('avf_postgrid_excerpt_length','avia_change_postgrid_excerpt_length', 10, 1);
    function avia_change_postgrid_excerpt_length($length)
    {
       $length = 100;
       return $length;
    }

    Best regards,
    Yigit

    #1335436

    Hi Yigit
    I already tried that code – in my main functions.php file – but it did not work?
    Any other suggestions?
    Kevin.

    #1335437

    I found this code:
    // Excerpt length
    function custom_excerpt(){
    ?>
    <script>
    // trim sentence by 22 words
    function trimByWord(sentence,wordcount = 22) {
    var result = sentence;
    var resultArray = result.split(” “);
    if(resultArray.length > wordcount){
    resultArray = resultArray.slice(0, wordcount);
    result = resultArray.join(” “) + “…”;
    }
    return result;
    }
    jQuery(window).load(function(){
    jQuery(‘.post-entry’).each(function() {
    jQuery(“.entry-content “).text(function(index, currentText) {

    return trimByWord(currentText);
    });
    jQuery(“.entry-title a”).text(function(index, currentText) {
    return trimByWord(currentText,15); // trim title by 15 words
    });
    });
    });
    </script>
    <?php
    }
    add_action(‘wp_head’, ‘custom_excerpt’);

    on this article:
    https://kriesi.at/support/topic/excerpt-length-and-read-more-blog-post-display/
    But did work – bit I was not sure if this was the best option?
    Kevin.

    #1335438

    Sorry, I meant to say – it did work! However, is this the better option?
    K

    #1335455

    Hey Kevin,

    Which element are you using? The code you posted uses jQuery. I think using filters would be better option.

    If you are using Magazine element, please use following code

    add_filter('avf_magazine_excerpt_length','avf_magazine_excerpt_new_lenght', 10, 1);
    function avf_magazine_excerpt_new_lenght($excerpt) {
    $excerpt = 100;
    return $excerpt;
    }

    If you are using Masonry element, please use following one

    add_filter( 'avf_masonry_excerpt_length', 'masonry_excerpt_length');
    function masonry_excerpt_length() {
    $excerpt = 200;
    return $excerpt;
    }

    And if you are using Accordion element, please use following

    add_filter( 'avf_aviaccordion_excerpt_length', 'slider_excerpt_length');
    function slider_excerpt_length() {
    $excerpt = 200;
    return $excerpt;
    }

    Regards,
    Yigit

    #1335478

    Hi Yigit,
    Yes this is now working on the blog page masonry, with 3 columns.
    However, I wanted it to work on the home page where i have the “latest news” with 4 columns – but I cannot seem to get this working?

    #1335667

    Hi,
    Thank you for your patience it looks like you are using version 4.7.6, please update to v4.8.8 and then check, if it is still not working please include an admin login in the Private Content area so we can investigate.

    Best regards,
    Mike

    #1415443

    Hi guys

    Can you confirm that the filter for the blog post element set in grid mode still works?

    I have a client asking me to shorten the excerpts and I cannot get the filter to work in 5.6.5

    
    add_filter('avf_postgrid_excerpt_length','avia_change_postgrid_excerpt_length', 10, 1);
    function avia_change_postgrid_excerpt_length($length)
    {
       $length = 100;
       return $length;
    }

    I am using the grid style blog posts ELEMENT on the home page with title and excerpts turned on.

    • This reply was modified 1 year, 3 months ago by thinkjarvis.
    #1415474

    Hi,
    Yes this works for classic editor posts:
    Enfold_Support_2818.jpeg
    Enfold_Support_2820.jpeg
    But not for ALB posts that have a manual excerpt:
    Enfold_Support_2822.jpeg
    This function works for both classic editor posts with automatic excerpts and ALB posts with manually add excerpts:

    add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_mod', 10, 4);
    function avf_post_slider_entry_excerpt_mod($excp, $prep, $perm, $entry) {
    	$excp = substr($excp, 0, 100);
    	return $excp;
    }

    Enfold_Support_2824.jpeg

    Best regards,
    Mike

    #1415606

    Hi Mike,

    Thank you for this. I can confirm it shortens the excerpt but the filter is stopping the read more button from generating.
    Is there a way to fix this?

    I have added a CSS class to add some dots after the content so it doesnt suddenly end.

    .slide-entry-excerpt::after {
    content:'...';
    }

    Is it possible for you to update the snippet?

    #1415613

    Hi,
    So does this mean that your posts are created with the ALB and the excerpts are manually added?

    Best regards,
    Mike

    #1415641

    Hi Mike,

    WHen using the ALB Blog Posts element > Set it to grid > set it to show title, excerpt and read more button.

    Because this code shortens the excerpt and the div containing the read more button is within the excerpt this code removes the read more button as well as shortening the excerpt.

    Is there a way to preserve the read more button?

    #1415643

    Hi,
    The original function Yigit posted works correctly for classic editor posts:

    add_filter('avf_postgrid_excerpt_length','avia_change_postgrid_excerpt_length', 10, 1);
    function avia_change_postgrid_excerpt_length($length)
    {
       $length = 100;
       return $length;
    }
    

    Enfold_Support_2845.jpeg
    But since this doesn’t seem to be working for you I assume that you have created the posts with the Advanced Layout Builder (ALB) and have manually added the excerpts:
    Enfold_Support_2847.jpeg
    In this case try this function:

    add_filter('avf_post_slider_entry_excerpt', 'avf_post_slider_entry_excerpt_mod', 10, 4);
    function avf_post_slider_entry_excerpt_mod($excp, $prep, $perm, $entry) {
    	$the_id = $entry->ID;
    	$permalink = '<div class="read-more-link"><a href="' . get_permalink( $the_id ) . '" class="more-link">' . __( 'Read more', 'avia_framework' ) . '<span class="more-link-arrow"></span></a></div>';
    	$excp = substr($excp, 0, 100).'...'.$permalink;
    	return $excp;
    }

    Enfold_Support_2849.jpeg

    Best regards,
    Mike

    #1415645

    Thanks Mike,

    This has worked.

    To get the elements the same height I have given them a minimum height via CSS.

    Thank you for your help.

    #1415647

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

    #1415680

    Some thoughts on excerpt:

    I think it would be generally better to remove the read more link from the excerpts and put it in the entry-footer before the meta information. For this you would only have to change the postslider.php in some places.
    In the ALB element is queried, as should be displayed – about the ID “contents” the value will then decide later, via switch and case contribute to how the output looks.

    So if we take the decisions whether to set read-more out of the excerpts and then put them in entry-footer, that should then give us the ability to limit the excerpts according to the above filter set by Mike without cutting the read-more link.

    see here in the DOM where the read-more link is : https://webers-testseite.de/blog/

    see here the edited postslider.php on pastebin: https://pastebin.com/PL15U0NN since lines 893-917 and for the entry-footer: 1227-1243

    i hope that this will go to the next update of enfold – because it makes sense to limit excerpt length but to preserve read-more link!

    #1415681

    PS: it would be nice to have a filter to limit excerpt on both : ALB posts and standard Post by word count.

    #1415701

    Hi,
    Guenni007 your idea for the excerpts is good please submit this feature request to the Dev Team Github Feature Request for Günter to review, he set it up for a central place to review them and reply to the authors. Thank you.
    As for my filter, I found an old post by Ismael and it worked for both types of excerpts, Classic & manual excerpts, and with a little hammering I got it to show the read more also.

    Best regards,
    Mike

    #1415747

    yes on former attempts i shift the read-more link via jQuery

    $('.avia-content-slider .read-more-link').each(function() {
        $(this).closest('.slide-entry').find('.entry-footer').prepend($(this));
    });

    to that entry-footer – but it would be better to have it just from the beginning on that place.

    #1415775

    Hi,
    Interesting, you were able to move the read-more button before the excerpt limiting function stripped it? I would have thought that the excerpt limiting function would have worked before the DOM so the jQuery would not find it.
    I’m glad this excerpt limiting function works on both types of excerpts, I didn’t know about your other point but I would still post it to the Github Feature Request because I think Yigit also works on these things.

    Best regards,
    Mike

    #1415929

    not before the filter – this is not possible – but with a different way ( that via word count) :

    function custom_excerpt_setting(){
    ?>
    <script>
    (function($){
    // trim excerpt by words
        function trimByWord(sentence,wordcount = 10) {
            var result = sentence;
            var resultArray = result.split(" ");
            if(resultArray.length > wordcount){
            resultArray = resultArray.slice(0, wordcount);
            result = resultArray.join(" ") + "...";
            }
            return result;
        }
        $(document).ready(function(){
            $('.avia-content-slider .read-more-link').each(function() {
                $(this).closest('.slide-entry').find('.entry-footer').prepend($(this));
            }); 
            
            $('.avia-content-slider .slide-entry-excerpt').each(function() {
                 $(this).text(function(index, currentText) {
                    return trimByWord(currentText);
                 });
            });
        });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_excerpt_setting');

    but as said above – it is better to influence the build process – than to shift it afterwards.
    The best place for the read more link is the entry-footer.

    #1415949

    Hi,
    I agree.

    Best regards,
    Mike

Viewing 23 posts - 1 through 23 (of 23 total)
  • The topic ‘how to adjust the excerpt length in ENFOLD’ is closed to new replies.