Last active
March 28, 2023 03:15
-
-
Save conor-egan/8454940 to your computer and use it in GitHub Desktop.
Remove hellip and final punctuation from a WordPress excerpt (includes rtrim function)
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
/* Custom Excerpt */ | |
// Remove default hellip | |
function carawebs_remove_hellip( $more ) { | |
return ''; | |
} | |
add_filter('excerpt_more', 'carawebs_remove_hellip'); | |
// Build a new excerpt with a nice Read More link | |
function carawebs_custom_excerpt() { | |
//pass the value of the excerpt string to the variable $str | |
$str = get_the_excerpt(); | |
//use the rtrim function to edit $str and pass the edited value the variable $trimmed | |
$trimmed = rtrim ( $str, ".,:;!?" ); | |
//configure the read more link with the excerpt preceding it | |
echo $trimmed; ?>…<br><a href="<?php echo get_permalink();?>">Read More…</a><?php | |
} | |
// Add to a Thesis 2.x hook | |
add_action ('hook_after_custom_excerpt', 'carawebs_custom_excerpt'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment