Title: Excerpts remove paragraph formatting?
Last modified: September 1, 2016

---

# Excerpts remove paragraph formatting?

 *  [michaelnicholas](https://wordpress.org/support/users/michaelnicholas-1/)
 * (@michaelnicholas-1)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/excerpts-remove-paragraph-formatting/)
 * Excerpts seem to be stripping out paragraph returns. Paragraphs exist on a post’s
   page, but an excerpt on the main page is just one big paragraph…
 * Is this by design?
 * You can see it here
    [http://storiesbymichaelnicholas.com](http://storiesbymichaelnicholas.com)
 * Thanks!

Viewing 1 replies (of 1 total)

 *  [Fotis](https://wordpress.org/support/users/markwaregr/)
 * (@markwaregr)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/excerpts-remove-paragraph-formatting/#post-7670048)
 * Hi there,
    excerpts are meant to be small paragraphs so they strip by default
   any html tags (like <p>). You can add this in the end of your functions.php to
   make paragraph tags visible in excerpts.
 *     ```
       function wpse_allowedtags() {
           // Add custom tags to this string
               return '<p>';
           }
   
       if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) : 
   
           function wpse_custom_wp_trim_excerpt($wpse_excerpt) {
           $raw_excerpt = $wpse_excerpt;
               if ( '' == $wpse_excerpt ) {
   
                   $wpse_excerpt = get_the_content('');
                   $wpse_excerpt = strip_shortcodes( $wpse_excerpt );
                   $wpse_excerpt = apply_filters('the_content', $wpse_excerpt);
                   $wpse_excerpt = str_replace(']]>', ']]>', $wpse_excerpt);
                   $wpse_excerpt = strip_tags($wpse_excerpt, wpse_allowedtags()); /*IF you need to allow just certain tags. Delete if all tags are allowed */
   
                   //Set the excerpt word count and only break after sentence is complete.
                       $excerpt_word_count = 75;
                       $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
                       $tokens = array();
                       $excerptOutput = '';
                       $count = 0;
   
                       // Divide the string into tokens; HTML tags, or words, followed by any whitespace
                       preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens);
   
                       foreach ($tokens[0] as $token) { 
   
                           if ($count >= $excerpt_length && preg_match('/[\,\;\?\.\!]\s*$/uS', $token)) {
                           // Limit reached, continue until , ; ? . or ! occur at the end
                               $excerptOutput .= trim($token);
                               break;
                           }
   
                           // Add words to complete sentence
                           $count++;
   
                           // Append what's left of the token
                           $excerptOutput .= $token;
                       }
   
                   $wpse_excerpt = trim(force_balance_tags($excerptOutput));
   
                       $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . ' » ' . sprintf(__( 'Read more about: %s  »', 'wpse' ), get_the_title()) . '</a>';
                       $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); 
   
                       //$pos = strrpos($wpse_excerpt, '</');
                       //if ($pos !== false)
                       // Inside last HTML tag
                       //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */
                       //else
                       // After the content
                       $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */
   
                   return $wpse_excerpt;   
   
               }
               return apply_filters('wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt);
           }
   
       endif; 
   
       remove_filter('get_the_excerpt', 'wp_trim_excerpt');
       add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
       ```
   
 * Try installing the WP Editor plugin to enhance the default editor and then navigate
   to the /themes/olsen-light/ folder to find the file.
 * Let me know if this works

Viewing 1 replies (of 1 total)

The topic ‘Excerpts remove paragraph formatting?’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/olsen-light/1.7.1/screenshot.png)
 * Olsen Light
 * [Support Threads](https://wordpress.org/support/theme/olsen-light/)
 * [Active Topics](https://wordpress.org/support/theme/olsen-light/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/olsen-light/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/olsen-light/reviews/)

## Tags

 * [excerpt](https://wordpress.org/support/topic-tag/excerpt/)
 * [formatting](https://wordpress.org/support/topic-tag/formatting/)
 * [paragraph](https://wordpress.org/support/topic-tag/paragraph/)

 * 1 reply
 * 2 participants
 * Last reply from: [Fotis](https://wordpress.org/support/users/markwaregr/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/excerpts-remove-paragraph-formatting/#post-7670048)
 * Status: not resolved