/*Reverse sticky header*/
  1. Home
  2. Knowledge Base
  3. Customizations
  4. Javascript
  5. How to Make the Post Comment Truncated with the Read More Button

How to Make the Post Comment Truncated with the Read More Button

By default, the platform does not have this option. You can use the following JavaScript code to make the post comment truncated and add “Read More” button

Please follow the steps below:

    1. Go to BuddyBoss – Theme Options.

    2. Under Custom Codes, enable JavaScript.

    3. Append the following:

jQuery(document).ready(function($) {
    $('.comment').each(function() {
        var fullText = $(this).find('.comment-text').text();
        var excerptLength = 200; // Adjust the excerpt length as needed

        if (fullText.length > excerptLength) {
            var excerpt = fullText.substring(0, excerptLength);
            var remainingText = fullText.substring(excerptLength);

            $(this).find('.comment-text').html(excerpt + '<span class="comment-excerpt">' + remainingText + '</span>' +
                '<a class="read-more-comment" href="#"> Read More</a>');

            $(this).find('.comment-excerpt').hide();

            $(this).on('click', '.read-more-comment', function(e) {
                e.preventDefault();
                var excerptElem = $(this).prev('.comment-excerpt');
                excerptElem.toggle();
                if (!excerptElem.is(':hidden')) {
                    $(this).hide();
                }
            });
        }
    });
});

    4. Click Save Changes.

Note: Any modifications are considered as custom work already. Know more about our Support Policy here: https://www.buddyboss.com/support-policy/

Screenshots

Without Code:

With Code:

Was this article helpful?

Related Articles

Contents

Need Support?

Can't find the answer you're looking for?
Contact Support

To speak to our Agency consultant, fill in the form found at our Contact Page.

"*" indicates required fields

Get Started

Enter your name and email address to get started with your project...

Name*