Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Limit WordPress Post excerpt to specific physical size

Posted on 2012-09-11
Medium Priority
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
ID: 38389623
Try switching to a character count solution:

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

Accepted Solution

Immanuel Kumar earned 2000 total points
ID: 38462216
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
ID: 38837227
Sorry for the delay. This one slipped past me.

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

580 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