Title: Customizing The_Excerpt
Last modified: August 21, 2016

---

# Customizing The_Excerpt

 *  [Krissy](https://wordpress.org/support/users/krissy/)
 * (@krissy)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/customizing-the_excerpt/)
 * I wasn’t able to locate this on Google, so I was hoping that someone could help
   me here.
 * I’m using the following code to customize the_excerpt output.
 *     ```
       function improved_trim_excerpt($text) {
               global $post;
               if ( '' == $text ) {
                       $text = get_the_content('');
                       $text = apply_filters('the_content', $text);
                       $text = str_replace('\]\]\>', ']]>', $text);
                       $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
                       $text = strip_tags($text, '<p> <em> <i> <b> <strong> <img>');
                       $excerpt_length = 50;
                       $words = explode(' ', $text, $excerpt_length + 1);
                       if (count($words)> $excerpt_length) {
                               array_pop($words);
                               array_push($words, 'read more...');
                               $text = implode(' ', $words);
                       }
               }
               return $text;
       }
       remove_filter('get_the_excerpt', 'wp_trim_excerpt');
       remove_action('wp_head', 'rel_canonical');
       add_filter('get_the_excerpt', 'improved_trim_excerpt');
       ```
   
 * Obviously on the page I’m calling the file I just put in the_excerpt()
 * What I’m wondering, would it be possible to make the_excerpt() a ‘conditional’
   kind of tag? A few areas of the site that I’m working on require no “read more”
   information, where as other sections do. Is there a way to modify the actual 
   call itself?
 * For example:
 * `<?php the_excerpt('no-read-more');?>`

Viewing 1 replies (of 1 total)

 *  [jnhghy](https://wordpress.org/support/users/jnhghy/)
 * (@jnhghy)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/customizing-the_excerpt/#post-4032291)
 * There are different ways you can achive this, most likely you’ll have to create
   a new variable that will save the setting:
    $noReadMore = 0 or $noReadMore = 
   1 and then depending on this variable display or don’t display the content

Viewing 1 replies (of 1 total)

The topic ‘Customizing The_Excerpt’ is closed to new replies.

## Tags

 * [customization](https://wordpress.org/support/topic-tag/customization/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [the_excerpt](https://wordpress.org/support/topic-tag/the_excerpt/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [jnhghy](https://wordpress.org/support/users/jnhghy/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/customizing-the_excerpt/#post-4032291)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
