Site logo

[Resolved] Limit characters of custom fields displayed with dynamic data

Home Forums Support [Resolved] Limit characters of custom fields displayed with dynamic data

Home Forums Support Limit characters of custom fields displayed with dynamic data

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #2384107
    David
    Staff
    Customer Support

    Sorry i didn’t change this line:

    && 'post-summary' === $block['attrs']['className']

    Can you make sure that has your CSS Class name

    #2384118
    Magnus

    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?

    #2384127
    David
    Staff
    Customer Support

    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;
    }
    #2384160
    Magnus

    The required CSS class is actually only embedded in the first three posts of that page: https://www.screencast.com/t/fKl4py13Y

    #2384277
    David
    Staff
    Customer Support
    #2384381
    Magnus
    #2384418
    David
    Staff
    Customer Support

    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;
    }
    #2385688
    Magnus

    Yes, the CSS Code works fine. Thank you

    #2385710
    David
    Staff
    Customer Support

    Glad to hear that!!

Viewing 9 posts - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.