Theme & Front End CSS Beginner

Limit Excerpts to Three Lines

Cut post card excerpts off after three lines with an ellipsis, so cards in a grid line up neatly.

Tested on WordPress 7.1 No plugin needed Updated
style.css 9 lines
/* Change the selector to match your theme's excerpt or card text. */
.entry-summary p,
.wp-block-post-excerpt__excerpt {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	overflow: hidden;
}

Where to add this

Recommended Additional CSS Appearance → Customize → Additional CSS, or your page builder's global CSS.
Child theme At the end of your child theme's style.css file.
A code snippets plugin As a CSS snippet set to load on the front end.

Excerpts of different lengths make post grids look ragged. Clamping them to the same number of lines keeps every card the same height without editing a single excerpt.

How it works

The line clamp properties show only the first three lines and add “…” where the text is cut. All current browsers support -webkit-line-clamp, including Firefox and Safari; line-clamp is the future standard name.

The full text is still in the page, so search engines and screen readers get all of it.

Things to watch

  • Change the selectors to match your theme. Inspect an excerpt in DevTools to find its class.
  • Line clamping only works on block-level text. If your excerpt is inside a link or span, target the paragraph inside it.

How to test it

Open your blog page. Every excerpt should stop after three lines with an ellipsis.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only