Skip to content

Instantly share code, notes, and snippets.

@carasmo
Last active June 6, 2023 18:22
Show Gist options
  • Save carasmo/0a5070299c2d89ab02c3 to your computer and use it in GitHub Desktop.
Save carasmo/0a5070299c2d89ab02c3 to your computer and use it in GitHub Desktop.
Force the read more link on excerpts even if the content is below the threshold and even if it's a custom excerpt.
<?php
//don't include this
/** ====================================================================================
* Force read more link to all excerpts whether or not it meets the word length criteria
* and whether or not it is a custom excerpt
==================================================================================== **/
function excerpt_more_link_all_the_time() {
// Remove More Link from get_the_excerpt()
function more_link() {
return '';
}
add_filter('excerpt_more', 'more_link');
//Force read more link on all excerpts
function get_read_more_link() {
$excerpt = get_the_excerpt();
return '<p>' . $excerpt . '&nbsp;...&nbsp;<a href="' . get_permalink() . '">Read&nbsp;More</a></p>';
}
add_filter( 'the_excerpt', 'get_read_more_link' );
}
add_action( 'after_setup_theme', 'excerpt_more_link_all_the_time' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment