Stripping shortcode from custom excerpt function

Don’t use a custom function. You should use the hooks. You don’t have to strip shortcodes, wordpress does that for you automatically, just use something like this

// setting higher priority so that wordpress default filter have already applied
add_filter('the_excerpt', 'custom_excerpt_filter', 11);
function custom_excerpt_filter($excerpt) {
    // apply your logic of read more link here
    return $excerpt . 'Custom Read More Text';
}

add_filter('excerpt_length', 'custom_excerpt_length');
function custom_excerpt_length($length) {
    return 30; // replace this with the character count you want
}

RULE OF THUMB

Never Ever create a custom function for something there is a hook or core function available

Leave a Comment