Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*============================================================
- Add Custom Excerpt Legnth
- ============================================================*/
- function custom_excerpt($new_length = 15, $new_more = 'Read more . . .') {
- // use the variable passed from $new_length as the length of the excerpt
- add_filter('excerpt_length', function () use ($new_length) {
- return $new_length;
- }, 999);
- // determine what comes at the end of the excerpt (in this case ...)
- add_filter('excerpt_more', function () use ($new_more) {
- return $new_more;
- });
- // generate the current excerpt
- $output = get_the_excerpt();
- // use wptexturize to basically sanitize the excerpt
- $output = apply_filters('wptexturize', $output);
- // convert_chars to remove metadata tags and convert others to unicode
- $output = apply_filters('convert_chars', $output);
- // wrap it back up in p tags
- // the above line may not be needed depending on the status of wpautop
- // echo that sucker
- echo $output;
- }
- /*============================================================
- Add Read More Link To Excerpt
- ============================================================*/
- function new_excerpt_more($more) {
- global $post;
- return '<a href="'. get_permalink($post->ID) . '"> Read more . . .</a>';
- }
- add_filter('excerpt_more', 'new_excerpt_more');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement