From 5fa4c984fde76402eb218692bbb898bd65f118c0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 17 Dec 2020 18:19:48 +0000 Subject: [PATCH] Twenty Nineteen: Add "Continue reading" link for post excerpts. This ensures that archive pages have a meaningful link text after the excerpts. Props metalandcoffee, alex27, sabernhardt, mdrockwell, laurelfulford. Fixes #46177. git-svn-id: https://develop.svn.wordpress.org/trunk@49831 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentynineteen/functions.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/wp-content/themes/twentynineteen/functions.php b/src/wp-content/themes/twentynineteen/functions.php index ed23d3e0d9..4fd0b76d6e 100644 --- a/src/wp-content/themes/twentynineteen/functions.php +++ b/src/wp-content/themes/twentynineteen/functions.php @@ -204,6 +204,30 @@ function twentynineteen_widgets_init() { } add_action( 'widgets_init', 'twentynineteen_widgets_init' ); +/** + * Replaces "[...]" (appended to automatically generated excerpts) with ... and + * a 'Continue reading' link. + * + * @since Twenty Nineteen 2.6 + * + * @param string $link Link to single post/page. + * @return string 'Continue reading' link prepended with an ellipsis. + */ +function twentynineteen_excerpt_more( $link ) { + if ( is_admin() ) { + return $link; + } + + $link = sprintf( + '', + esc_url( get_permalink( get_the_ID() ) ), + /* translators: %s: Post title. */ + sprintf( __( 'Continue reading "%s"', 'twentynineteen' ), get_the_title( get_the_ID() ) ) + ); + return ' … ' . $link; +} +add_filter( 'excerpt_more', 'twentynineteen_excerpt_more' ); + /** * Set the content width in pixels, based on the theme's design and stylesheet. *