Title: Custom Excerpt Function
Last modified: August 20, 2016

---

# Custom Excerpt Function

 *  [Dani-Girl](https://wordpress.org/support/users/dani-girl/)
 * (@dani-girl)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/custom-excerpt-function/)
 * I have the following code to control the amount of characters in my excerpt to
   show on a page:
 *     ```
       function get_my_excerpt(){
       $excerpt = get_the_content();
       $excerpt = substr($excerpt, 0, 200);
       $excerpt = strip_shortcodes($excerpt);
       $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
       $excerpt = strip_tags($excerpt);
       $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
       $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
       $excerpt = $excerpt.'... [Read More]';
       return $excerpt;
       }
       ```
   
 * I can’t for the life of me remember how to code this part:
    $excerpt = $excerpt.’…[
   Read More]’;
 * so that the [Read More] links to the post for further reading associated to the
   post it’s for.
 * Can someone help?

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

 *  [jon](https://wordpress.org/support/users/adiant/)
 * (@adiant)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/custom-excerpt-function/#post-2924997)
 * I think the first line of code in the “How to add a link beneath an excerpt to
   the full post” section on this page is what you want:
    [http://codex.wordpress.org/Excerpt#How_to_add_a_link_beneath_an_excerpt_to_the_full_post](http://codex.wordpress.org/Excerpt#How_to_add_a_link_beneath_an_excerpt_to_the_full_post)
 *  Thread Starter [Dani-Girl](https://wordpress.org/support/users/dani-girl/)
 * (@dani-girl)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/custom-excerpt-function/#post-2925000)
 * That won’t work in this call:
 * $excerpt = $excerpt.’… [Read More]’;
 *  [jon](https://wordpress.org/support/users/adiant/)
 * (@adiant)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/custom-excerpt-function/#post-2925010)
 * Why not? You would end up with this, which I haven’t tested, but should work:
   `
   $excerpt = $excerpt . '<a href="' . get_permalink() . '">... [Read More]</a>';`

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

The topic ‘Custom Excerpt Function’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [jon](https://wordpress.org/support/users/adiant/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/custom-excerpt-function/#post-2925010)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
