Title: Remove shortcode from content
Last modified: August 19, 2016

---

# Remove shortcode from content

 *  Resolved [EntarteteMuzak](https://wordpress.org/support/users/entartetemuzak/)
 * (@entartetemuzak)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/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: [http://wordpress.org/support/topic/remove-short-code-from-excerpt?replies=4#post-1924799](http://wordpress.org/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.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [EntarteteMuzak](https://wordpress.org/support/users/entartetemuzak/)
 * (@entartetemuzak)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/remove-shortcode-from-content/#post-2011520)
 * Can I use the [strip shortcode](http://codex.wordpress.org/Function_Reference/strip_shortcodes)
   function?
 *  Thread Starter [EntarteteMuzak](https://wordpress.org/support/users/entartetemuzak/)
 * (@entartetemuzak)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/remove-shortcode-from-content/#post-2011654)
 * Fixed it with this:
 * in Functions
 *     ```
       <?php
       add_filter( 'the_excerpt', 'remove_columns' );
       function remove_columns( $excerpt ) {
       	return preg_replace ("/\[(\S+)\]/e", "", $excerpt);
       }?>
       ```
   
 * In template:
    `<?php remove_all_shortcodes('the_excerpt') ; the_excerpt(); ?>`
 * The only thing that ticks me is that the […] after the excerpt disappears if 
   I use this technique on the excerpt.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Remove shortcode from content’ is closed to new replies.

## Tags

 * [excerpt](https://wordpress.org/support/topic-tag/excerpt/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [Short Code](https://wordpress.org/support/topic-tag/short-code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [EntarteteMuzak](https://wordpress.org/support/users/entartetemuzak/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/remove-shortcode-from-content/#post-2011654)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
