Archived topic
Limit characters of custom fields displayed with dynamic data
23 replies · Started by Magnus on October 22, 2022
Sorry i didn't change this line:
&& 'post-summary' === $block['attrs']['className']
Can you make sure that has your CSS Class name
I use your code like this
add_filter( 'render_block', function( $block_content, $block ) {
if (
!is_admin()
&& is_single()
&& ! empty( $block['attrs']['className'] )
&& 'post-summary' === $block['attrs']['className']
&& $summary
) {
$block_content = wp_trim_words( $block_content, 40 );
}
return $block_content;
}, 10, 2 );
and the additional css class for the content block is 'post-summary'. But it's not working. Maybe I should use CSS only to solve this?
I don't see the class on that block:
https://www.screencast.com/t/6y5tI2Bjdt
Pure CSS solution to set a limit on the number of lines:
.post-summary {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
The required CSS class is actually only embedded in the first three posts of that page: https://www.screencast.com/t/fKl4py13Y
This is the URL i was checking:
https://ride-with-love.bike/transalp-enduro-bike-beste-routen/
Please Check this Page: https://ride-with-love.bike/stilfser-joch-die-besten-trails-suedtirols/
Aah ok ... so that is a single post too, and i assume it too has the trail_summary Custom Field - which explains why earlier ALL of the posts retured the same summary,
Can you try this CSS :
.post-summary {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
Yes, the CSS Code works fine. Thank you
Glad to hear that!!