Remove visual composer shortcodes from content in wordpress


<?php
/* Get only listed posts */
$test_array = array(‘335’, ‘328’, ‘970’);

$query = new WP_Query( array( ‘post_type’ => ‘testimonials’, ‘post__in’ => $test_array ) );

global $post;

/* Get Post url */
$page_url = get_permalink($post->ID);

/* Get Post congtent */
$content = $post->post_content;

/* Remove visual composer shortcode like [vc_row] link that */
$desc = strip_tags(do_shortcode($post->post_content));

/* Remove empty spaces */
$desc = trim(preg_replace(‘/\s+/’,’ ‘, $desc ));

/* Get content with limit */
$desc = mb_strimwidth($desc, 0, 200, ‘…’);

?>

Advertisement

4 thoughts on “Remove visual composer shortcodes from content in wordpress

  1. how do i actually use this? I need to strip all VC shortcodes and leave the content behind in all pages and posts, how do i do this? Cheers

    Like

  2. Thanks for asking.

    Have you maintained page templates for individual pages or default template for all pages we have to use above code in php page template file.

    I think this answer is fine otherwise let me know plz..

    Like

    • they are all based on the default page templates in the theme so i just add the PHP to the pages? Thanks for getting back to me

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s