Skip Navigation

[Resolved] excerpt with read more collapsible

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 1 voice.

Last updated by hoogeshD 1 week, 3 days ago.

Assisted by: Minesh.

Author
Posts
#2814687
2025-07-02 11 00 41.jpg

Tell us what you are trying to do?
I need an excerpt, so have a few lines, then have a read more button that shows the rest of the text (dynamic body).

Is there any documentation that you are following?
No

Is there a similar example that we can see?
hidden link

What is the link to your site?
hidden link

#2814707

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To achive that we need to add custom JS/jQuery code.

Can you please send me admin access details and let me try to check what is the possible solution/workaround.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2814711
2025-07-02 17 53 34.jpg
2025-07-02 17 54 10.jpg

Hello Minesh,
Before we do this, I think I can achieve what I am trying to do with the more block, hidden link
I am using a single field to load the body. However, on display on the front-end, it removes the more functionality.

#2814729

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As you shared the link - if you check the link, the more block will have effect on archive pages not on single post pages.

For single post pages, you will have to use the custom javascript/jQuery workaround. If you can share admin access details I will check to see what would bhe the possible workaround in your case.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2815096

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

I've added the CSS class "right-column-page-content" to your single field block that displays the post body content and added the following code to "Custom Javascript" section of the content template:
- hidden link

jQuery(document).ready(function($) {
  var contentEl = $('.right-column-page-content');
  var fullHTML = contentEl.html().trim();
  var charLimit = 250;

  // Create a temporary container to parse the HTML while preserving structure
  var tempEl = $('<div>').html(fullHTML);
  var visibleHTML = '';
  var totalChars = 0;

  // Walk through the nodes and preserve HTML until limit is reached
  tempEl.contents().each(function() {
    if (totalChars >= charLimit) return;

    var clone = $(this).clone();
    var text = clone.text();

    if ((totalChars + text.length) <= charLimit) {
      visibleHTML += $('<div>').append(clone).html();
      totalChars += text.length;
    } else {
      var partialText = text.substring(0, charLimit - totalChars);
      clone.text(partialText + '...');
      visibleHTML += $('<div>').append(clone).html();
      totalChars = charLimit;
    }
  });

  if (totalChars < fullHTML.length) {
    var toggleHTML = `
      <div class="short-text">${visibleHTML}</div>
      <div class="full-text" style="display:none;">${fullHTML}</div>
      <a href="#" class="read-more-toggle">Read More</a>
    `;
    contentEl.html(toggleHTML);

    contentEl.on('click', '.read-more-toggle', function(e) {
      e.preventDefault();
      var $this = $(this);
      contentEl.find('.short-text, .full-text').toggle();
      $this.text($this.text() === 'Read More' ? 'Read Less' : 'Read More');
    });
  }
});

Can you please check now it works as expected.

More info:
- https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/#steps-for-adding-javascript-to-a-template

#2815350

Exactly what I needed. This can be a very interesting feature.