Last active
October 15, 2016 21:01
-
-
Save timothyjensen/7484f6147142cfab32260ac6ad88fb6a to your computer and use it in GitHub Desktop.
Customize the default more link, and add that custom link to manual excerpts
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 | |
add_filter( 'excerpt_more', 'tj_excerpt_more_link' ); | |
/** | |
* Modify the excerpt more link for standard excerpts | |
* | |
* @param string, default read more link | |
* @return string, modified read more link | |
*/ | |
function tj_excerpt_more_link( $more ) { | |
$more_link = tj_custom_more_link(); | |
return $more_link; | |
} | |
add_filter( 'get_the_excerpt', 'tj_manual_excerpt_more' ); | |
/** | |
* Add the custom more link to manual excerpts | |
* | |
* @param string, $excerpt, manual excerpt | |
* @return string, manual excerpt with appended more link | |
*/ | |
function tj_manual_excerpt_more( $excerpt ) { | |
if ( ! has_excerpt() ) | |
return $excerpt; | |
$more_link = tj_custom_more_link(); | |
return $excerpt . $more_link; | |
} | |
/** | |
* Build the custom more link | |
* | |
* @return string, customized more link | |
*/ | |
function tj_custom_more_link() { | |
$more_link = '<a class="more-link" href="' . get_permalink() . '">Read More ...</a>'; | |
return $more_link; | |
} | |
add_filter( 'excerpt_length', 'avo_excerpt_length', 999 ); | |
/** | |
* Reduce the excerpt length to 16 words | |
* | |
* @param $length | |
* @return int | |
*/ | |
function avo_excerpt_length( $length ) { | |
return 16; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment