Title: remove &#8216;[]&#8217; shortcode text in excerpts
Last modified: August 19, 2016

---

# remove ‘[]’ shortcode text in excerpts

 *  [kendkoll](https://wordpress.org/support/users/kendkoll/)
 * (@kendkoll)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/remove-shortcode-text-in-excerpts/)
 * I would like to remove the “[ ]” from the end of excerpts, can someone tell me
   how to do this
 * Thanks

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

 *  [mrsolutions](https://wordpress.org/support/users/mrsolutions/)
 * (@mrsolutions)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/remove-shortcode-text-in-excerpts/#post-1062919)
 * also would like to know how to do this
 *  [mrsolutions](https://wordpress.org/support/users/mrsolutions/)
 * (@mrsolutions)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/remove-shortcode-text-in-excerpts/#post-1062924)
 * I had a look into this. In normal circumstances I think wordpress does it automatically.
   You should be able to find this code in the formatting.php file or another file(
   can’t remember which).
 *     ```
       $text = str_replace(']]>', ']]>', $text);
       $text = strip_tags($text, $allowed_tags);
       ```
   
 * However, a plugin may interfere, such as a plugin for advanced excerpts or any
   plugin involved in creating an excerpt.
 * Therefore make sure that code is in there. So you may want to study the plugin’s
   code and add that code to it. I added the following and it got rid of most unwanted
   code in excerpts:
 *     ```
       $text = str_replace(']]>', ']]>', $text);
       $text = preg_replace('@.*?</script>@si', '', $text); //remove javascript
       $text = preg_replace('@<![\s\S]*?--[ \t\n\r]*>@', '', $text); // remove CDATA
       $text = strip_tags($text, $allowed_tags);
       $text = preg_replace('<code>\[[^\]]*\]</code>','',$text); //remove anything in square brackets
       ```
   

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

The topic ‘remove ‘[]’ shortcode text in excerpts’ is closed to new replies.

## Tags

 * [excerpts](https://wordpress.org/support/topic-tag/excerpts/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [mrsolutions](https://wordpress.org/support/users/mrsolutions/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/remove-shortcode-text-in-excerpts/#post-1062924)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
