WordPress.org

Ready to get started?Download WordPress

Forums

remove '[]' shortcode text in excerpts (3 posts)

  1. kendkoll
    Member
    Posted 5 years ago #

    I would like to remove the "[ ]" from the end of excerpts, can someone tell me how to do this

    Thanks

  2. mrsolutions
    Member
    Posted 5 years ago #

    also would like to know how to do this

  3. mrsolutions
    Member
    Posted 5 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic