Last active
May 16, 2018 04:58
-
-
Save jamiebergen/48d41daa1ec6ffe3bc6276d8506ab3bc to your computer and use it in GitHub Desktop.
[Read more link for excerpts] Accessible and translatable "read more" link #wordpress #theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Makes the excerpt "read more" a link to the full post | |
*/ | |
// Case for automatically generated excerpts | |
function jmb_sample_theme_excerpt_more( $more ) { | |
global $post; | |
$permalink = get_permalink($post->ID); | |
$title = get_the_title(); | |
$excerpt_more = jmb_sample_theme_get_read_more_link( $permalink, $title ); | |
return $excerpt_more; | |
} | |
add_filter( 'excerpt_more', 'jmb_sample_theme_excerpt_more' ); | |
// Case for hand-crafted excerpts | |
function jmb_sample_theme_manual_excerpt_more( $excerpt ) { | |
$excerpt_more = ''; | |
if ( has_excerpt() && !is_attachment() && get_post_type() == 'post' ) { | |
$permalink = get_permalink(); | |
$title = get_the_title(); | |
$excerpt_more = jmb_sample_theme_get_read_more_link( $permalink, $title ); | |
} | |
return $excerpt . $excerpt_more; | |
} | |
add_filter( 'get_the_excerpt', 'jmb_sample_theme_manual_excerpt_more' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment