Hi vishypat,
yes – there is already an function for this.
Btw. there is an option to set the custom excerpt length, please navigate to “Appearance => Customize => General Options” in your WordPress dashboard and just set the excerpt length there – that’s it.
For the custom read more link, please add this function to the functions.php of your child theme:
if (!function_exists('custom_excerpt')) {
function custom_excerpt($text = '') {
$raw_excerpt = $text;
if ('' == $text) {
global $post;
$options = get_option('mh_options');
$custom_length = empty($options['excerpt_length']) ? '35' : $options['excerpt_length'];
$text = get_the_content('');
$text = do_shortcode($text);
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = apply_filters('excerpt_length', $custom_length);
$excerpt_more = apply_filters('excerpt_more', ' ...');
$text = wp_trim_words($text, $excerpt_length, $excerpt_more);
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_excerpt');
}
And then just modify:
$excerpt_more = apply_filters('excerpt_more', ' ...');
Regards
Michael
Seems like the above code will not work for manual excerpt. Was able to use your function custom_excerpt to achieve what I needed.
Thanks
Ok – looks like we posted at the same time… 🙂
As I said, you can use the above function to solve your issue.
Regards
Michael