Title: set excerpt length
Last modified: July 20, 2020

---

# set excerpt length

 *  Resolved [Bam Bam](https://wordpress.org/support/users/bam-bam/)
 * (@bam-bam)
 * [6 years ago](https://wordpress.org/support/topic/set-excerpt-length-2/)
 * Hi guys,
 * Still loving the plugin, got a small question I hope you can help me with, I 
   am playing around with another Posts Grid block and I want to set the excerpt
   length and can’t quite figure it out.
 * I have tried adding the following but it doesn’t work.
 *     ```
       $args = array(
       	'the_excerpt'    => array( 20 )
           );
       ```
   
 * I also tried this, but again it didn’t work.
 * `<p><?php the_excerpt( 20 ); ?></p>`
 * I have no real understanding of php, it kind of does my head in.
 * Sorry I can’t give you a link to the dev site.
 * Kindest Regards
    Bam Bam
    -  This topic was modified 6 years ago by [Bam Bam](https://wordpress.org/support/users/bam-bam/).
    -  This topic was modified 6 years ago by [Bam Bam](https://wordpress.org/support/users/bam-bam/).
    -  This topic was modified 6 years ago by [Bam Bam](https://wordpress.org/support/users/bam-bam/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [smrdo](https://wordpress.org/support/users/smrdo/)
 * (@smrdo)
 * [6 years ago](https://wordpress.org/support/topic/set-excerpt-length-2/#post-13146246)
 * Hi, what does your Block Template look like?
 * Ive limited the excerpt like this,
    in your functions.php add
 *     ```
       //limit length of Excerpt
       function limit_words($string, $word_limit) {
       	// creates an array of words from $string (this will be our excerpt)
       	// explode divides the excerpt up by using a space character
       	$words = explode(' ', $string);
       	// this next bit chops the $words array and sticks it back together
       	// starting at the first word '0' and ending at the $word_limit
       	// the $word_limit which is passed in the function will be the number
       	// of words we want to use
       	// implode glues the chopped up array back together using a space character
       	return implode(' ', array_slice($words, 0, $word_limit));
        }
       ```
   
 * Im using the “post” block type to display a chose post, in the template im using
   the following to display & limit the exerpt..
 * `<?php echo limit_words(get_the_excerpt(block_sub_value( 'your-block-type-sub-
   value' )->ID), '55'); ?>`
 * mines a sub-value as its in a repeater field, so adjust that as necessary..
 * hope that helps?
 *  Thread Starter [Bam Bam](https://wordpress.org/support/users/bam-bam/)
 * (@bam-bam)
 * [6 years ago](https://wordpress.org/support/topic/set-excerpt-length-2/#post-13147102)
 * This is the whole php for this block.
 *     ```
       <?php
           // Variables
   
           $post_count = block_value( 'number-of-posts' );
           $post_type  = block_value( 'post-type' );
   
   
           // WP_Query arguments
           $args = array(
               'post_type'      => array( $post_type ),
               'posts_per_page' => $post_count,
       	'category__in'   => array( 40 ),
           );
   
           // The Query
           $post_grid_query = new WP_Query( $args );	
   
           // The Loop
           while ( $post_grid_query->have_posts() ) {
               $post_grid_query->the_post();
               ?>
   
               <div class="block-the-norwegian-posts--post">
                   <div class="block-the-norwegian-posts--post-thumbnail" style="background-image: url('<?php the_post_thumbnail_url( 'large' ); ?>');">
                   </div>
                   <div class="block-the-norwegian-posts--post-content">
                       <a href="<?php the_permalink(); ?>">
       		    <h4 align="center"><?php the_title(); ?>
       		</a>
       		</h4>
                       <p><?php the_excerpt(); ?></p>
                       <a class="read-more" href="<?php the_permalink(); ?>">Read More</a>
                   </div>
               </div>
   
               <?php
           }
   
           // Restore original Post Data
           wp_reset_postdata();
           ?>
       ```
   
 *  Thread Starter [Bam Bam](https://wordpress.org/support/users/bam-bam/)
 * (@bam-bam)
 * [6 years ago](https://wordpress.org/support/topic/set-excerpt-length-2/#post-13147587)
 * Never mind I’m an idiot sometimes, I hadn’t actually created an excerpt, all 
   sorted.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘set excerpt length’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/block-lab_5c34e8.svg)
 * [Block Lab](https://wordpress.org/plugins/block-lab/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/block-lab/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/block-lab/)
 * [Active Topics](https://wordpress.org/support/plugin/block-lab/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/block-lab/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/block-lab/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Bam Bam](https://wordpress.org/support/users/bam-bam/)
 * Last activity: [6 years ago](https://wordpress.org/support/topic/set-excerpt-length-2/#post-13147587)
 * Status: resolved