When utilizing shortcode (plugin, etc.) near the top of the page, the plugin shortcode displays in the preview. Is there a way to hide text within brackets [text like this] from a preview on a recent posts type of page?

The following example shows the shortcode within a blog post preview:

Example of Brackets within Preview

  • 1
    If you don't want shotcodes in excerpt then why not to just write one? Commented Oct 15, 2015 at 17:12
  • Interesting, to manually replace the excerpt, when editing the blog post where do I go to write that? I do not have it as an option.
    – beta208
    Commented Oct 15, 2015 at 17:14
  • Thank you, that was correct. I simply needed to enable 'Screen Options > Excerpt'.
    – beta208
    Commented Oct 15, 2015 at 17:15

4 Answers 4


You can do with PHP. Just remove part where is get_content() and add this:

            $content = preg_replace('#\[[^\]]+\]#', '',$content);
            echo apply_filters('the_content', $content);

That is regular expression added inside content. This regex will remove all tags inside content.


Use this instead if you don't wanna manually write excerpts every time:

function wpse205632_filter_excerpt( $excerpt ) {

    $excerpt = strip_shortcodes( $excerpt );

    return $excerpt;
add_filter( 'get_the_excerpt', 'wpse205632_filter_excerpt' );  

Just add this snippet in functions.php and you are good to go.

  • I would agree that it's better to use strip_shortcodes() than custom reg-exp..
    – birgire
    Commented Nov 27, 2015 at 12:16

Excerpt was not showing but would do the trick. On the edit post page, accessing 'Screen Options' and selecting 'Excerpt' allows one to manually fill the excerpt.


This is what I used to get content as excerpt with limited amount of words, and exclude shortcodes from Visual Composer

<?php $content=get_the_content(); $content = preg_replace('#\[[^\]]+\]#', '',$trimmed_content = wp_trim_words($content, 20)); echo apply_filters('the_content', $content, $trimmed_content); ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.