Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a variable like this:

$post_content = get_the_content();

Here i want to remove some specific shortcode from the $post_content variable e.g i want to remove only this [video height="300" width="300" mp4="localhost.com/video.mp4"] all other shortcodes and content formatting should be leaved intact.

How could this be done?

UPDATE:

I'm able to remove some specific shortcode by using code something like this ...

<?php echo do_shortcode( str_replace('[video height="300" width="300" mp4="localhost.com/video.mp4"]', '', get_the_content()) ); ?>

But it is also removing all html tags/formatting of get_the_content(). How to avoid it?

share|improve this question

1 Answer 1

Wouldn't it be

$post_content_without_shortcodes = strip_shortcodes(get_the_content());

or there's also

$post_content_without_shortcodes = remove_all_shortcodes(get_the_content());
share|improve this answer
    
No, i dont want to remove all shortcodes from the content. Just want to remove some specific shortcode having specific attributes. e.g i want to remove only this [video height="300" width="300" mp4="localhost.com/video.mp4"] all other shortcodes and content formatting should be leaved intact. –  Faisal79c2 Jan 26 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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