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