WordPress.org

Support

Support » Themes and Templates » Custom the_excerpt with “read more” link..

Custom the_excerpt with “read more” link..

  • Hi guys,
    my template uses the_excerpt. If i customize the excerpt in the backend (underneath the normal post-text i can set a custom excerpt) the frontpage (index.php) doesn’t show the …read more? link. Only if i let wordpress cut the first 50 words for a post-excerpt it does show this link. However i also want the read more link if i customize the excerpt for a post by hand.

    <div class="entry-content">
    			   <?php the_excerpt(); ?>
              </div>

    function.php

    function link_hellip_in_excerpt( $content ) {
    	global $post_ID;
    	return preg_replace( '~\[\.\.\.\]$~', ' <a href="' . get_permalink( $post_ID ) . '">...weiterlesen?</a>', $content);
    }
    add_filter( 'the_excerpt', 'link_hellip_in_excerpt', 9);
    add_filter( 'the_content', 'link_hellip_in_excerpt', 9);

    The thing is, if i customize an excerpt wordpress doesn’t create a […] at the end of a post.

    ??? any ideas?

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

    @esmi

    Forum Moderator

    Try adding the following to your theme’s functions.php file:

    // Increase excerpt length
    function my_excerpt_length($length) {
    	return 100; // Or whatever you want the length to be.
    }
    add_filter('excerpt_length', 'my_excerpt_length');

    Then in your template file, you could use:

    <?php the_excerpt();?>
    <a class="more-link" href="<?php the_permalink();?>"><?php _e('Continue reading');?> <?php the_title();?></a>

    Won’t the second solution cause a duplicate read more if the length exceeds the excerpt limit?

    Try adding the following to your theme’s functions.php file:

    function excerpt_ellipse($text) {
       return str_replace('[...]', ' <a href="'.get_permalink().'">Continue...</a>', $text);
    }
    add_filter('get_the_excerpt', 'excerpt_ellipse');
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom the_excerpt with “read more” link..’ is closed to new replies.
Skip to toolbar