Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/639716131184451584
Improved formatting and removed the scrollbar in the codebox
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

I have a variable like this:

$post_content = get_the_content();

Here iI want to remove some specific shortcode from the $post_content variable e.g iI 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()get_the_content(). How to avoid it?

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?

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?

added 325 characters in body
Source Link

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?

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?

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?

deleted 736 characters in body; edited title
Source Link

Grab Remove specific shortcode from the content and remove from itget_the_content()

I have a variable like this:

$post_content = get_the_content();

I have two requirements here:

1: IHere i want a function to grab the first occurrence of any specific shortcode e.g [video] and returns that shortcode ONLY. Which can then be used in do_shortcode() optionally.

2: Remove thatremove some specific shortcode ONLY 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 cancould this be done?

UPDATE 1:

Ok, regarding point one, i found a method which grabs any specific shortocode from the content and stores it in a variable. Here you can find the method: http://stackoverflow.com/questions/6290810/return-only-the-shortcode-from-post

check answer of: two7s_clash

But it works only if our shortcode is the first shortcode in that post, if there is any shortcode before it, it will not grab the shortcode.

UPDATE 2:

Found the solution for the first question. Now only want to know about second question

Grab specific shortcode from the content and remove from it

I have a variable like this:

$post_content = get_the_content();

I have two requirements here:

1: I want a function to grab the first occurrence of any specific shortcode e.g [video] and returns that shortcode ONLY. Which can then be used in do_shortcode() optionally.

2: Remove that specific shortcode ONLY 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 can this be done?

UPDATE 1:

Ok, regarding point one, i found a method which grabs any specific shortocode from the content and stores it in a variable. Here you can find the method: http://stackoverflow.com/questions/6290810/return-only-the-shortcode-from-post

check answer of: two7s_clash

But it works only if our shortcode is the first shortcode in that post, if there is any shortcode before it, it will not grab the shortcode.

UPDATE 2:

Found the solution for the first question. Now only want to know about second question

Remove specific shortcode from get_the_content()

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?

added 15 characters in body
Source Link
Loading
added 152 characters in body
Source Link
Loading
added 423 characters in body
Source Link
Loading
corrected something, which i really want to say
Source Link
Loading
Source Link
Loading