WordPress.org

Make WordPress Core

Ticket #13361: cautiously_fancy_excerpts.diff

File cautiously_fancy_excerpts.diff, 1.8 KB (added by iandstewart, 4 years ago)

Generate a "Continue Reading" link, filter excerpt_more and--if there's a custom excerpt--filter get_the_excerpt to add our generated link to trimmed excerpts AND custom excerpts but NOT posts less than the excerpt length.

  • functions.php

     
    249249add_filter( 'excerpt_length', 'twentyten_excerpt_length' ); 
    250250 
    251251/** 
    252  * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis. 
     252 * Returns a "Continue Reading" link for excerpts 
    253253 * 
     254 * @since Twenty Ten 1.0 
     255 * @return string "Continue Reading" link 
     256 */ 
     257function twentyten_continue_reading_link() { 
     258        return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>'; 
     259} 
     260 
     261/** 
     262 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link(). 
     263 * 
    254264 * To override this in a child theme, remove the filter and add your own 
    255265 * function tied to the excerpt_more filter hook. 
    256266 * 
     
    258268 * @return string An ellipsis 
    259269 */ 
    260270function twentyten_auto_excerpt_more( $more ) { 
    261         return ' &hellip;'; 
     271        return ' &hellip;' . twentyten_continue_reading_link(); 
    262272} 
    263273add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' ); 
    264274 
    265275/** 
    266  * Adds a pretty "Continue Reading" link to post excerpts. 
     276 * Adds a pretty "Continue Reading" link to custom post excerpts. 
    267277 * 
    268278 * To override this link in a child theme, remove the filter and add your own 
    269279 * function tied to the get_the_excerpt filter hook. 
     
    272282 * @return string Excerpt with a pretty "Continue Reading" link 
    273283 */ 
    274284function twentyten_custom_excerpt_more( $output ) { 
    275         return $output . ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>'; 
     285        if ( has_excerpt() ) { 
     286                $output .= twentyten_continue_reading_link(); 
     287        } 
     288        return $output; 
    276289} 
    277290add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' ); 
    278291