Remove shortcode from content
-
I’m trying to remove all short code from post content when I display the post in a search result. As it were, I also use short code in excerpts. I’ve found this solution, but I can’t seem to make it work: https://www.ads-software.com/support/topic/remove-short-code-from-excerpt?replies=4#post-1924799
Here is my code (the short code I’m trying to remove is
[col-sect]
and[column]
, as used by WP Columnize plugin)In functions:
<?php add_filter( 'the_excerpt', 'remove_columns' ); function remove_columns( $excerpt ) { return preg_replace ('/\[column[^\]]*\](.*)\[\/column\]/', '$1', $excerpt); return preg_replace ('/\[col-sect[^\]]*\](.*)\[\/col-sect\]/', '$1', $excerpt); }?>
In page:
<?php remove_filter('the_excerpt', 'do_shortcode') ; add_filter ('the_excerpt', 'remove_columns') ; the_excerpt(); ?>
I’ve added a remove filter on
do_shortcode
to remove the short code function from the excerpt, but that still leaves[col-sect]
and[column]
in the text. Also it seems that the first and the last occurrence of the[column]
is removed but not the rest, while both instances of[col-sect]
stays intact.
- The topic ‘Remove shortcode from content’ is closed to new replies.