Limit Post Titles and Excerpts to a Few Lines in Grids
Cuts long post titles to two lines and excerpts to three lines in blog grids and Query Loop blocks, so cards line up neatly whatever the text length.
Opens WPIDE on
Code
.wp-block-post-template .wp-block-post-title,
.blog .entry-title,
.archive .entry-title {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
overflow: hidden;
}
.wp-block-post-template .wp-block-post-excerpt__excerpt,
.blog .entry-summary p,
.archive .entry-summary p {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
line-clamp: 3;
overflow: hidden;
}
Notes
Change the line counts in -webkit-line-clamp. Full titles still show on single posts.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.