WordPress.org

Ready to get started?Download WordPress

Forums

Custom the_excerpt with "read more" link.. (4 posts)

  1. sepp88
    Member
    Posted 4 years ago #

    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?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    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>
  3. Spencer Hill
    Member
    Posted 3 years ago #

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

  4. Fask
    Member
    Posted 3 years ago #

    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');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.