I have a need for the Power Query's nested excerpt block to be a fixed height, which means it is 2 lines tall, whether the excerpt text is 1 line or 3 lines. Is it possible to fix a block's height?

I know an excerpt block can be limited in words or characters (with a custom function) but neither of those are ideal for my situation.

I'm looking for a solution for WordPress 6.4+ and desktop (i.e., mobile isn't important). Thank you.

  • I can't imagine how you'd calculate an HTML element's length in lines. Changes in font, font size, etc will change how many lines a given bit of text occupies. Your best might be something CSS-based, like defining a height and hiding any overflowing text.
    – Pat J
    Commented Jan 24 at 0:35

1 Answer 1


Yes, you can fix the height of a Power Query's nested excerpt block in WordPress to ensure it is always two lines tall, regardless of the actual length of the excerpt. This can be achieved with CSS. The goal is to set a fixed height that corresponds to the line height of two lines of text in your theme. Here's how you can do it:

Determine the Selector: First, you need to identify the correct CSS selector for the excerpt block. This will depend on the structure of your theme and any specific classes that Power Query might add. You can use your browser's developer tools to inspect the excerpt block and find the appropriate selector.

Set Fixed Height and Overflow: Once you have the selector, you can add custom CSS to your theme that sets a fixed height and handles any overflow (text that exceeds the two lines). The overflow property can be set to hidden to hide any excess text.

Adding Custom CSS: In WordPress 6.4+, you can add custom CSS directly through the WordPress Customizer. Go to Appearance → Customize → Additional CSS. Here's an example of what your CSS might look like:

.your-excerpt-selector {
    height: 3em; /* Adjust this value based on your theme's line height */
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;

In this example, replace .your-excerpt-selector with the actual selector for your excerpt block. The height property should be adjusted based on the line height and font size of your theme to accommodate exactly two lines of text.

Responsive Considerations: Although you mentioned mobile isn't important, it's good practice to ensure that your CSS doesn't negatively impact the mobile layout. You can use media queries to apply this styling only on desktop views.

Test and Adjust: After applying these styles, test them on your site to see how they look with different lengths of excerpt text. Adjust the height as necessary to ensure it consistently shows two lines of text.

Remember, the exact values for height will depend on your theme's font size and line height, so some experimentation might be necessary to get it just right. Also, consider that hiding overflow text means that some longer excerpts will be cut off and not fully readable, so ensure this aligns with your site's user experience goals.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.