✔ Posts - Not showing read more if there is no excerpt display or there is a custom excerpt
Completed by Kyle S.
- Assigned to
-
Kyle S.
- Notes
-
The Read More to view the post should show basically no matter what, right now it doesn't show if there is no text (say there is an image in the post Weekly Message may not be there any more according to this to-do) or when there is a custom excerpt (See FAQ post)
https://judetheapostle.diocesanweb.org/category/news/
<?php /** * Custom excerpt functions * * @package dpiChild */ // Limit excerpt length to 30 words if( ! function_exists( 'limit_excerpt_length' ) ) { function limit_excerpt_length( $length ) { return 30; } add_filter( 'excerpt_length', 'limit_excerpt_length', 999 ); } // Limit custom excerpt length to 30 words if( ! function_exists( 'custom_excerpt_length' ) ) { function custom_excerpt_length( $excerpt, $post = null ) { if( has_excerpt( $post ) ) { $excerpt_length = apply_filters( 'excerpt_length', 30 ); $excerpt_more = apply_filters( 'excerpt_more', ' ' . '' ); $excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more ); } return $excerpt; } add_filter( 'get_the_excerpt', 'custom_excerpt_length', 999, 2 ); } // Always include Read More link in excerpts if( ! function_exists('read_more_excerpt')) { function read_more_excerpt( $text, $post = null ) { return $text . '…<a href="'.get_the_permalink().'" class="read-more-link" title="Read More" rel="nofollow">Read More</a>'; } add_filter('get_the_excerpt', 'read_more_excerpt', 999, 2); } // Remove [...] from excerpts if( ! function_exists( 'new_excerpt_more' ) ) { function new_excerpt_more( $more ) { return ''; } add_filter('excerpt_more', 'new_excerpt_more'); } // Excerpt function for Ministry Cards if( ! function_exists('ministry_excerpt')) { function ministry_excerpt( $post = null ) { $excerpt_length = 30; $excerpt_more = '<a href="'.get_the_permalink().'" class="read-more-link" title="Read More" rel="nofollow">Read More</a>'; $text = get_the_content( '' ); $text = apply_filters('the_content', $text); $text = str_replace('\]\]\>', ']]>', $text); $text = str_replace(' ', ' ', $text); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $text = strip_tags($text, '<a>'); if(str_word_count($text, 0) > $excerpt_length) { $words = str_word_count($text, 2); $pos = array_keys($words); $text = substr($text, 0, $pos[$excerpt_length]); } $text = sprintf('<p>%s…</p>%s', $text, $excerpt_more); return $text; } }