-
Paully
Hi, I have added an excerpt to the excerpt section of a post. I have tried shortening the length a couple of ways (and purged the cache) but neither of them seem to work.
1 – Appearance > Customize > Layout > Blog > Changed to 20 (It didn’t work)
2 – Within the (Magazine Latest Posts) Element query loop template. Data Source (Current Post), Content Source (Excerpt), Excerpt Length (20). Still didn’t work.Can you help please?
(page in the private area) -
Hi there,
Try this PHP snippet:
add_filter( 'wp_trim_excerpt', 'yh_trim_custom_excerpt' ); function yh_trim_custom_excerpt( $excerpt ) { $output = $excerpt; // Limit word count to 20 $words_limit = 20; $excerpt_words = preg_split('/[\s]+/', $excerpt, $words_limit + 1); if (count($excerpt_words) > $words_limit) { array_pop($excerpt_words); $excerpt = implode(' ', $excerpt_words); } if ( has_excerpt() ) { $output = sprintf( '%1$s... <a href="%2$s">%3$s</a>', $excerpt, get_permalink(), __( 'Read more', 'generatepress' ) ); } return $output; }
-
Paully
Thanks Ying, that’s perfect.
-
You are welcome 🙂
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.