Limit WordPress Post excerpt to specific physical size

Posted on 2012-09-11
Last Modified: 2013-01-30
My theme is a magazine style layout. On the front page, I have four columns that each show a preview of the most recent post from four different categories.

I would like for all of the excerpts to fill the allotted space and to display the <more...> link.

It is easy enough to set up a widget that posts a specific number of words, but because words come in many different sizes, I may have two excerpt that each contain 30 words, but one may take up five lines and the one next to it seven.

I can make a div to display the excerpt with the overflow set to hidden, but that hides the <more...> link at the end.

How can I make my post previews fill a specific space so that they each match each other?Desired outcome
Question by:David Brugge
    LVL 70

    Expert Comment

    by:Jason C. Levine
    Try switching to a character count solution:

    <?php $little_excerpt = substr(the_excerpt(),0,X); ?>
    LVL 2

    Accepted Solution

    Hi,put this code in the template function.php

    function string_limit_words($string, $word_limit)
      $words = explode(' ', $string, ($word_limit + 1));
      if(count($words) > $word_limit)
      return implode(' ', $words);

    and call this in your display page.

      $excerpt = get_the_excerpt();
      echo string_limit_words($excerpt,25);
    Thank You
    LVL 26

    Author Closing Comment

    by:David Brugge
    Sorry for the delay. This one slipped past me.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    How to create your own WordPress Theme Before I begin with the theme design tutorial, I would like to give you the basics of what is required to make a WordPress Theme. The most basic WordPress theme only requires 2 files: a style.css file and an…
    Wordpress Horizontal Drop-Down Menu In this tutorial I will show you had to add a WordPress horizontal navigation menu to your theme. I have searched and searched for a good tutorial on creating a WordPress nav menu without adding a plug-in or us…
    The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
    The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now