Title: Read more function
Last modified: May 25, 2021

---

# Read more function

 *  [yda5](https://wordpress.org/support/users/yda5/)
 * (@yda5)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/)
 * Hey,
    I have implemented this code into my functions.php file
 *     ```
       function new_excerpt_more($more) {
              global $post;
       	return '<a>ID) . '"> read more...</a>';
       }
   
       add_filter('excerpt_more', 'new_excerpt_more', 99);
       ```
   
 * , because i wanted to add read more for my posts on my home page. but it seems
   that it works only for some posts, and not for all of them.
    Do you know why 
   maybe?
    -  This topic was modified 5 years ago by [yda5](https://wordpress.org/support/users/yda5/).
    -  This topic was modified 5 years ago by [yda5](https://wordpress.org/support/users/yda5/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fread-more-function-7%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14481214)
 * The “more” is only added if the text is longer than the ‘excerpt_length’.
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14481215)
 * Without commenting on why you need to do this ………
 * Your code above shouldn’t be working at all.
    You aren’t using a link to the 
   a anywhere – it should be more like this:
 *     ```
       function new_excerpt_more($more) {
       	global $post;
       	return '<a href="' . $post-->ID . "' . > read more...</a>';
       }
       add_filter('excerpt_more', 'new_excerpt_more', 99);
       ```
   
 *  Thread Starter [yda5](https://wordpress.org/support/users/yda5/)
 * (@yda5)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14481657)
 * So how can i extend it to work for all of the posts? [@joyously](https://wordpress.org/support/users/joyously/)
 * The code the you sent, doesn’t work at all, it gives me an error when i’m trying
   to save. [@corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14481694)
 * Oops – syntax error fixed:
 *     ```
       function new_excerpt_more($more) {
       	global $post;
       	return '<a href="' . $post->ID . "' . > read more...</a>';
       }
       add_filter('excerpt_more', 'new_excerpt_more', 99);
       ```
   
 * or this:
 *     ```
       function new_excerpt_more($more) {
       	global $post;
       	return '<a href="' . $post->ID . "' . > read more...</a>';
               // or maybe this:
               // echo get_permalink($post->ID);
   
       }
       add_filter('excerpt_more', 'new_excerpt_more', 99);
       ```
   
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14481704)
 * Don’t rely on the length of the excerpt if you want a link on everything. Output
   the excerpt as is (no filter), then output the link to the post.
 *  Thread Starter [yda5](https://wordpress.org/support/users/yda5/)
 * (@yda5)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14481836)
 * I don’t why buy these codes just don’t work.. it gives me error again. [@corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * And practically, how can i do it ? haha [@joyously](https://wordpress.org/support/users/joyously/)
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14482048)
 * I tested this one on my own site:
 *     ```
       function new_excerpt_more($more) {
               global $post;
               return '<a href="' . $post->ID . '" . > read more...</a>';
               // or maybe this:
               // echo get_permalink($post->ID);
   
       }
       add_filter('excerpt_more', 'new_excerpt_more', 99);
       ```
   
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14482401)
 * “excerpt_more” filtering still only works on longer posts. To have a link after
   content no matter how short the content is, you can add something like `<a href
   ="<?php the_permalink(); ?>">Permalink</a>` to the appropriate theme template
   right after content is output. Preferably a template for a child theme.
 * Instead of altering templates, use “the_content” filter and concatenate the anchor
   tag shown above to the passed content.
 *  Thread Starter [yda5](https://wordpress.org/support/users/yda5/)
 * (@yda5)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14482601)
 * Ok, but under which folder should i insert this of code?
    Sorry, i have a basic
   knowledge on the code stuff.
 *  Thread Starter [yda5](https://wordpress.org/support/users/yda5/)
 * (@yda5)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14482604)
 * Or maybe there is another way to add “read more” to my website, I don’t know,
   i was thinking that is something basic that should be on every proper website..
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/)
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14483153)
 * It is very likely that there is already a link to the post, on the title or the
   featured image or both. Not every site uses “read more” links since it looks 
   cluttered and there are already links.
    If you are determined to add it, you 
   can create a child theme and change the template, or you can add a filter for`
   the_excerpt` (not “the_content” as suggested above) and concatenate the link 
   on the end. [https://developer.wordpress.org/reference/hooks/the_excerpt/](https://developer.wordpress.org/reference/hooks/the_excerpt/)
   Be sure to make it accessible. Or you can choose a theme that already does this.
 *  Thread Starter [yda5](https://wordpress.org/support/users/yda5/)
 * (@yda5)
 * [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14483778)
 * Thank you! i Used this code and it worked:
 *     ```
       add_filter( 'excerpt_more', '__return_empty_string', 21 );
   
       function wpse_134143_excerpt_more_link( $excerpt ) {
           $excerpt .= sprintf( 
                   '... <a href="%s">%s</a>.',
                   esc_url( get_permalink() ),
                   __( 'continue reading' )
           );
           return $excerpt;
       }
       add_filter( 'the_excerpt', 'wpse_134143_excerpt_more_link', 21 );
       ```
   

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

The topic ‘Read more function’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 12 replies
 * 4 participants
 * Last reply from: [yda5](https://wordpress.org/support/users/yda5/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/read-more-function-7/#post-14483778)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
