Site logo

Archived topic

Limit characters of custom fields displayed with dynamic data

23 replies · Started by Magnus on October 22, 2022

Viewing posts 16–24 of 24

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;
}

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!!

This archived topic is closed to new replies.