(Squarespace) Limit number of characters in Blog Pagination Text on Mobile

To limit the number of characters in Blog Pagination Text on Mobile, from this.

To this

You can use this code to Code Injection > Footer

<script>
document.addEventListener('DOMContentLoaded', function() {
  const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth < 768;
  
  if (isMobile) {
    const MAX_EXCERPT_LENGTH = 20;
    const excerptWrappers = document.querySelectorAll('.item-pagination[data-collection-type^="blog"]');
    
    excerptWrappers.forEach(wrapper => {
      const paragraphs = wrapper.querySelectorAll('.item-pagination-title');
      
      paragraphs.forEach(paragraph => {
        const text = paragraph.textContent;
        if (text.length > MAX_EXCERPT_LENGTH) {
          paragraph.textContent = text.substring(0, MAX_EXCERPT_LENGTH) + '...';
        }
      });
    });
  }
});
</script>

You can change number of characters here.

1 Like