Title: PHP Question&#8230;
Last modified: August 19, 2016

---

# PHP Question…

 *  [nickaster](https://wordpress.org/support/users/nickaster/)
 * (@nickaster)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/)
 * Hey guys,
 * Right now I’m displaying post excerpts on my Tag templates as follows:
 * ‘<?php strip_tags( the_excerpt() ); ?>’
 * Sometimes, however, the excerpt is too long and messes up the page layout. How
   can I force the exceprt to cut off after a certain number of words or characters?
   Like this:
 * ‘<?php strip_tags( the_excerpt(CUT OFF AFTER 100 CHARS) ); ?>’
 * THANKS!!!

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

 *  [Clayton James](https://wordpress.org/support/users/claytonjames/)
 * (@claytonjames)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1730739)
 * Is it possible to just add a filter to lower the default excerpt length similar
   to something like this?
    [ Control Excerpt Length using Filters
 * Or would that cause conflict in this case with excerpts used elsewhere on your
   site? Just for my own curiosity, does “strip_tags” have any effect on the_excerpt
   in this case? – or would html be automatically stripped anyhow? Just ball-parking,
   mind you. I guess I really don’t know for sure.
 *  [DigitalSquid](https://wordpress.org/support/users/twelvefootsnowman/)
 * (@twelvefootsnowman)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1730744)
 * Maybe something like:
 *     ```
       $length = 30; //Or whatever number of words you want
       $excerpt = strip_tags(get_the_excerpt());
       $words = explode(' ', $excerpt);
       if(count($words) > $length ){
           array_splice($words, $count);
           $excerpt = implode(' ', $words);
       }
       echo $excerpt;
       ```
   
 *  Thread Starter [nickaster](https://wordpress.org/support/users/nickaster/)
 * (@nickaster)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1731006)
 * Thanks guys… I don’t understand where all that php would go… this is in the tag.
   php template. Can you lay it out within the example I have above?
 * Thanks!
 *  [DigitalSquid](https://wordpress.org/support/users/twelvefootsnowman/)
 * (@twelvefootsnowman)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1731007)
 * Yup, just replace `<?php strip_tags( the_excerpt() ); ?>` with:
 *     ```
       $length = 30; //Or whatever number of words you want
       $excerpt = strip_tags(get_the_excerpt());
       $words = explode(' ', $excerpt);
       if(count($words) > $length ){
           array_splice($words, $count);
           $excerpt = implode(' ', $words);
       }
       echo $excerpt;
       ```
   
 * In your tag.php template.
 *  [Simon Prosser](https://wordpress.org/support/users/pross/)
 * (@pross)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1731008)
 * or simply add to functions.php
 *     ```
       function new_excerpt_length($length) {
       	return 20;
       }
       add_filter('excerpt_length', 'new_excerpt_length')
       ```
   
 *  Thread Starter [nickaster](https://wordpress.org/support/users/nickaster/)
 * (@nickaster)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1731010)
 * okay, super.. thanks… one more clarification. for functions.php, sure I can add
   that, but do i just slap in there exactly as you have it written? And then the
   code I have on tag.php doesn’t need to be changed?
 * Thanks!
 *  [Simon Prosser](https://wordpress.org/support/users/pross/)
 * (@pross)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1731024)
 * The code I posted will change the excerpt length wherever `get_the_excerpt()`
   is called

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

The topic ‘PHP Question…’ is closed to new replies.

 * 7 replies
 * 4 participants
 * Last reply from: [Simon Prosser](https://wordpress.org/support/users/pross/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/php-question-7/#post-1731024)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
