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
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(
'',
'',
get_the_content()
)
);
?>
But it is also removing all html tags/formatting of get_the_content()
. How to avoid it?
If you want exactly this shortcode:
to output nothing, then you can use the
wp_video_shortcode_override
filter or thewp_video_shortcode
filter to achieve that.Here are two such examples:
Example #1
Example #2
Note
I would recommend the first example, because there we are intercepting it early on and don’t need to run all the code within the shortcode callback.
You can use php preg_replace core function to search for your shortcode in content and remove it so your code may be :
Wouldn’t it be
or there’s also