How to limit post content and remove image caption from it

Image captions in WordPress are actually shortcodes.
Shortcodes are applied by the filter:

$content = apply_filters('the_content', $content);

For example, WordPress creates the following code in your content when you enter an image caption:

Here is my caption

You need to still use apply_filters() in order to properly display content. (safe content display and all other shortcodes)

If you don’t want shortcodes (which is what it looks like, since you are doing a striptags) you should just use this:

 $content = strip_shortcodes( $content );

But if it is specifically shortcodes, I assume this could work, if you just want to add a string-replace line to your code:

$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove  shortcode
$content = preg_replace("/\/", '', $content);
// short codes are applied
$content = apply_filters('the_content', $content);

Leave a Comment