Title: excerpt_length and WP_query
Last modified: August 21, 2016

---

# excerpt_length and WP_query

 *  Resolved [reddo](https://wordpress.org/support/users/reddo/)
 * (@reddo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/excerpt_length-and-wp_query/)
 * Hi.
 * Is there a way that I could set a new excerpt length before a custom wp_query
   and reset it after the query is done?

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

 *  [Evan Herman](https://wordpress.org/support/users/eherman24/)
 * (@eherman24)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/excerpt_length-and-wp_query/#post-4796164)
 * I use this function on my site:
 *     ```
       function get_excerpt($count){
         $permalink = get_permalink($post->ID);
         $excerpt = get_the_content();
         $excerpt = strip_tags($excerpt);
         $excerpt = substr($excerpt, 0, $count);
         $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
         $excerpt = $excerpt.'... <a class="link" href="'.$permalink.'">read more</a>';
         return $excerpt;
       }
       ```
   
 * That goes inside of your functions.php file.
 * When you want to display the exceprt in your loop you can just do:
 *     ```
       <?php echo get_excerpt(250); ?>
       ```
   
 * where 250 is the length of the excerpt.
 * Evan
 *  Thread Starter [reddo](https://wordpress.org/support/users/reddo/)
 * (@reddo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/excerpt_length-and-wp_query/#post-4796174)
 * I’ll give it a go. This number is in characters, not words, right?
 * I could wrap this in a <p> and add that read more link after it…
 * I’m open to other suggestions too though if anyone has a different approach.
 *  [Evan Herman](https://wordpress.org/support/users/eherman24/)
 * (@eherman24)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/excerpt_length-and-wp_query/#post-4796175)
 * Yea, 250 is the length of characters. You can do whatever you’d like to it.
 * `<p><?php echo get_excerpt(250); ?></p>`
 * The ‘read more’ link will appear after the last character you have specified.
   If you don’t want it there, but to just truncate and end, you can remove the ‘
   Read More’ link from the function above.
 * Just one route, and the easiest/quickest I have found.
 *  Thread Starter [reddo](https://wordpress.org/support/users/reddo/)
 * (@reddo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/excerpt_length-and-wp_query/#post-4796214)
 * Tried it, working like a charm!
 * Thanks for the tip!

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

The topic ‘excerpt_length and WP_query’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [reddo](https://wordpress.org/support/users/reddo/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/excerpt_length-and-wp_query/#post-4796214)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
