Title: the_excerpt(); adding &lt;p&gt;&lt;/p&gt;
Last modified: August 19, 2016

---

# the_excerpt(); adding <p></p>

 *  [oldnumber9](https://wordpress.org/support/users/oldnumber9/)
 * (@oldnumber9)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/the_excerpt-adding-ltpgtltpgt/)
 * In my index (in the loop) I call <?php the_excerpt(); ?> and it reterns the information
   fine except that it is adding additional P tags to the end.
 * Here is what it is generating
 * `<p>Text goes here fine [...]</p><p></p>`
 * I’ve read a ton of posts about the_excerpt(); wrapping content in P tags and 
   have also experimented with wp_trim_excerpt to remove the tags, but removing 
   the tags is only removing the P tags that are wrapping the content (I would actually
   like to keep those).
 * Does anyone have any clue as to where these extra <p></p> on the end might be
   generated from, or have a good work around?

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

 *  [nickathome](https://wordpress.org/support/users/nickathome/)
 * (@nickathome)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/the_excerpt-adding-ltpgtltpgt/#post-1126903)
 * Could you reproduce the code here that is doing that? Just the call to the_excerpt()
   and a couple of lines around it should do.
 * Without seeing the code, what I suspect is happening is that you’re trying to
   assign the result of the_excerpt() to a variable which you then wrap in a <p>
   to output.
 * But the_excerpt will just do the output within a <p> on its own and the variable
   you assign will (I’m pretty sure) be empty, hence the <p></p> when you write 
   it out wrapped.
 * Try get_the_excerpt() instead. It’s mentioned [here in the codex](http://codex.wordpress.org/Plugin_API/Filter_Reference)
   but that’s all.
 * But I had a similar thing where I had to change the_ID() to get_the_ID() so am
   guessing there’s a convention there.
 *  Thread Starter [oldnumber9](https://wordpress.org/support/users/oldnumber9/)
 * (@oldnumber9)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/the_excerpt-adding-ltpgtltpgt/#post-1126911)
 * OK here is the code that I am using (the issue is towards the bottom):
 *     ```
       <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
       <div id="<?php foreach((get_the_category()) as $category) {echo $category->cat_name . '-'; } ?>tag">
       <!-- VARIABLE CAT IMAGE -->
       <?php
       $the_cat = get_the_category();
       $category_name = $the_cat[0]->cat_name;
       $category_description = $the_cat[0]->category_description;
       $category_link = get_category_link( $the_cat[0]->cat_ID ); ?>
       <a href="<?php echo $category_link; ?>"><img title="<?php echo $category_description; ?>" src="<?php bloginfo('template_url'); ?>/images/<?php echo $category_name; ?>-tag.png" alt="<?php echo $category_name; ?>" /></a>
       </div>
       <!-- THUMB IMAGE -->
       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
       <img src="<?php $values = get_post_custom_values("thumb"); echo $values[0]; ?>" alt="<?php the_title(); ?>" class="thumb" /></a>
       <!-- HEADING -->
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
       <span class="entry"><?php the_excerpt(); ?></span>
       </div>
       ```
   
 * And this is what is generated:
 *     ```
       <div class="post-46 post hentry category-nw" id="post-46">
       <div id="news-tag">
       <!-- VARIABLE CAT IMAGE -->
       <a href="http://www.oldnumbernine.com/mcjh/?cat=3">
       <img title="" src="http://www.oldnumbernine.com/mcjh/wp-content/themes/default/images/news-tag.png" alt="news" /></a>
       </div>
       <!-- THUMB IMAGE -->
       <a href="http://www.oldnumbernine.com/mcjh/?p=46" title="and another one"><img src="http://www.oldnumbernine.com/mcjh/wp-content/uploads/2009/07/GripTrixPhoto-180x180.jpg" alt="and another one" class="thumb" /></a>
       <!-- HEADING -->
       <h2><a href="http://www.oldnumbernine.com/mcjh/?p=46" rel="bookmark" title="Permanent Link to and another one">and another one</a></h2>
       <span class="entry"><p>eu quam, turpis amet Pellentesque fames mi habitant vitae morbi ultricies ultricies tempor sit semper. ac eget, egestas. quam et tortor placerat [...]</p><p></p></span>
       </div>
       ```
   
 * Hope thats not too much information.
 * EDIT: get_the_excerpt() returns nothing for me. Just an empty span.
 *  [nickathome](https://wordpress.org/support/users/nickathome/)
 * (@nickathome)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/the_excerpt-adding-ltpgtltpgt/#post-1126950)
 * Instead of:
 * `<span class="entry"><?php the_excerpt(); ?></span>`
 * Do:
 * `<span class="entry"><?php echo(get_the_excerpt()); ?></span>`
 * That worked for me.
 * The excerpt could have it’s own <p></p> in it as well if you’ve entered it explicitly,
   eg using headspace2 or something.

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

The topic ‘the_excerpt(); adding <p></p>’ is closed to new replies.

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [nickathome](https://wordpress.org/support/users/nickathome/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/the_excerpt-adding-ltpgtltpgt/#post-1126950)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
