WordPress.org

Support

Support » How-To and Troubleshooting » remove ‘[]’ shortcode text in excerpts

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
    Member

    @mrsolutions

    also would like to know how to do this

    mrsolutions
    Member

    @mrsolutions

    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.