Ticket #13361: fancier_excerpts.diff

File fancier_excerpts.diff, 1.8 KB (added by iandstewart, 3 years ago)

Filter excerpt_more and--if there's a custom excerpt--filter get_the_excerpt to add a pretty "Continue reading" link to trimmed excerpts AND custom excerpts but NOT posts less than the excerpt length.

Line 
1Index: functions.php
2===================================================================
3--- functions.php       (revision 14875)
4+++ functions.php       (working copy)
5@@ -244,18 +244,32 @@
6 add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
7 
8 /**
9- * Sets the "read more" link to something pretty.
10+ * Replaces the traditional "[…]" for marking of excerpts with a pretty "Continue Reading" link
11  *
12+ * @since Twenty Ten 1.0
13+ * @return replace the traditional "[…]" for marking of excerpts with a pretty "Continue Reading" link
14+ */
15+function twentyten_auto_excerpt_more( $more ) {
16+       return $more .= ' &hellip; <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';;
17+}
18+add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
19+
20+/**
21+ * Adds a pretty "Continue Reading" link to custom post excerpts
22+ *
23  * To override this link in a child theme, remove the filter and add your own
24  * function tied to the excerpt_more filter hook.
25  *
26  * @since Twenty Ten 1.0
27- * @return string A pretty 'Continue reading' link.
28+ * @return add a pretty "Continue Reading" link to custom post excerpts
29  */
30-function twentyten_excerpt_more( $more ) {
31-       return ' &hellip; <a href="'. get_permalink() . '">' . __('Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten') . '</a>';
32+function twentyten_custom_excerpt_more( $output ) {
33+       if ( has_excerpt() ) {
34+               $output .= ' &hellip; <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
35+       }
36+       return $output;
37 }
38-add_filter( 'excerpt_more', 'twentyten_excerpt_more' );
39+add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
40 
41 /**
42  * Remove inline styles printed when the gallery shortcode is used.