Last active
August 13, 2022 18:09
-
-
Save jgoslow/dc41b06977a468ef93a9f0f4ed541bb3 to your computer and use it in GitHub Desktop.
Wordpress Excerpt PHP Functions
This file contains hidden or 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
/** | |
* Filter the except length to 20 words. | |
* | |
* @param int $length Excerpt length. | |
* @return int (Maybe) modified excerpt length. | |
*/ | |
function wpdocs_custom_excerpt_length( $length ) { | |
return 20; | |
} | |
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 ); |
This file contains hidden or 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
/** | |
* Filter the "read more" excerpt string link to the post. | |
* | |
* @param string $more "Read more" excerpt string. | |
* @return string (Maybe) modified "read more" excerpt string. | |
*/ | |
function wpdocs_excerpt_more( $more ) { | |
return sprintf( '<a class="read-more" href="%1$s">%2$s</a>', | |
get_permalink( get_the_ID() ), | |
__( 'Read More', 'textdomain' ) | |
); | |
} | |
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment