$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>posts - Remove Shortcode [...] from Blog Preview|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

posts - Remove Shortcode [...] from Blog Preview

matteradmin7PV0评论

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:

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:

Share Improve this question asked Oct 15, 2015 at 16:50 beta208beta208 1911 silver badge13 bronze badges 3
  • 1 If you don't want shotcodes in excerpt then why not to just write one? – Mark Kaplun 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
Add a comment  | 

4 Answers 4

Reset to default 2

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

<?php 
            $content=get_the_content();
            $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.

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); ?

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far