Support » Plugin: Display Posts Shortcode » [Plugin: Display Posts Shortcode] How to add a read more link or […] at the end of excerpt

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Bill Erickson


    I’ve updated the code snippet to add … to the end of the excerpt. I changed this:

    be_truncate_phrase( get_the_excerpt(), 50 ) . ‘</p>’

    To this:

    be_truncate_phrase( get_the_excerpt(), 50 ) . ‘…</p>’



    Thanks a lot for your support! It helped!

    I apologize for jumping in this thread late, but this is what I’m looking for. I would like shorter excerpts with a read more link.

    Can you tell me where one should implement the code you posted in github?

    Thanks in advance!

    Plugin Author Bill Erickson


    The code can be added to your theme’s functions.php file.

    This plugin is one of my favorite- I wish there is a way to add read more at the end of the excerpt. I dont want to modify the code that will be over written after the update

    Sorry, but I am not sure of where to place the code:

    be_truncate_phrase( get_the_excerpt(), 50 ) . ‘…</p>’

    I can’t find any code like that anywhere in my files.

    I agree, this is an excellent plugin and I really appreciate the flexibility.

    I too would like a “read more” link or “continue reading.” That’s my 2 cents 🙂



    This is what i did

    1. go to plugins, find Display posts shortcode press edit
    2. in the file “display-posts-shortcode/display-posts-shortcode.php” go to the bottom of the edit page and paste the code from this page >
    3. where it says … (use ctrl-f), replace … with read more.. or whatever.

    Plugin Author Bill Erickson


    Please do not place that in the plugin itself. When the plugin is updated, the code will be lost.

    That code can go in your theme’s functions.php file.

    If you change the code just a tiny bit you can add a “read more” with a link to the post at the end.

    * Edit our excerpt output
    add_filter( 'display_posts_shortcode_output', 'update_excerpt_format', 10, 7 );
    function update_excerpt_format( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
    	// First check if an excerpt is included by looking at the shortcode $atts
    	if ( $atts['include_excerpt'] )
    		// Now let's rebuild the excerpt with the read more link at the end
    		$read_more ='<p><a href="'.get_permalink() . '"> Read More...</a></p>';
                    //Now we can truncate
    		$excerpt = '<p><span class="excerpt">' . truncate_phrase( get_the_excerpt(), 150) . $read_more . '</span></p>';
    	else $excerpt = '';
    	// Now let's rebuild the output. Only the excerpt changed so we're using the original $image, $title, and $date
    	$output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . '</' . $inner_wrapper . '>';
    	// Finally we'll return the modified output
    	return $output;
     * Truncate Excerpt
    function truncate_phrase($phrase, $max_characters) {
    	$phrase = trim( $phrase );
    	if ( strlen($phrase) > $max_characters ) {
    		// Truncate $phrase to $max_characters + 1
    		$phrase = substr($phrase, 0, $max_characters + 1);
    		// Truncate to the last space in the truncated string.
    		$phrase = trim(substr($phrase, 0, strrpos($phrase, ' ')));
    	return $phrase;
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Display Posts Shortcode] How to add a read more link or […] at the end of excerpt’ is closed to new replies.