StoriedCorey reacted to
RyanDejaegher in Custom CSS To Limit Blog Excerpt
@StoriedCorey and @emilykrause Add this code to Settings -> Advanced -> Code Injection -> Footer
You can adjust the var characterCount to a different number to adjust how much it cuts off. You can also adjust the "trail".
This code will also only cut full words, that way it doesn't cut it at weird points. i.e. "Learn more about Squaresp...."
<script>
(function(){
window.addEventListener('load', function() {
var characterCount = 140
var blogParagraph = document.querySelectorAll('.BlogList-item-excerpt p')
var trail = "..."
// Shorten a string to less than maxLen characters without truncating words.
function shorten(str, maxLen, separator = ' ') {
if (str.length <= maxLen) return str;
return str.substr(0, str.lastIndexOf(separator, maxLen));
}
blogParagraph.forEach(item => {
item.textContent = shorten(item.textContent, characterCount) + trail;
})
})
})()
</script>
Result/Demo: