I have a section in my header that shows 2 excerpts from the latest posts which are potentially from a regular blog post or custom post. The custom posts are utilising Advanced Custom Fields to show a video, a description and some other things in the single.php. Because of this I needed to change some things about the excerpt filters in my functions.php file. This all works perfectly but the problem is that the description can be less than 15 words which seems to be my minimum for the excerpt_more filter which means that I don't get a '...Read More' link or anything else to allow a user to click through into the post. Here is my code for this section:
function new_excerpt_length($length) {
return 15;
}
add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"><br>...Read More</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
function custom_field_excerpt() {
global $post;
$text = get_field('description');
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 15;
$excerpt_more = apply_filters('excerpt_more', ' ');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more);
}
return apply_filters('the_excerpt', $text);
}
Is there something I could add to this or perhaps change the new_excerpt_more function in some way to always add a 'Read More' instead of just if it meets the 15 word minimum?