Wordpress remove shortcode from content

混江龙づ霸主 提交于 2019-12-04 16:30:51

Strange. remove_shortcode (codex link) doesn't take a second argument.

You're returning either the true or false return of the remove_shortcode function, not the content with the shortcode removed.

Try either something like this in that second version of your function up there:

remove_shortcode('gallery');
return $content;

Or just put

 remove_shortcode('gallery');

In your functions.php file. The previous poster suggested including the [ ]'s, which I guess is wrong.

I know this is a relative old question, but the strip_shortcodes function does work!

global $post;
echo strip_shortcodes($post->post_content);

Easiest way if you ask me..

I think you should use sub string replacement like this:

function remove_gallery($content) {
    return str_replace('[gallery]', '', $content);
}
add_filter( 'the_content', 'remove_gallery', 6); 

Bear in mind, this method does not come with good performance.

update: You can unregister the shotcode in function.php by adding code:

remove_shortcode('[gallery]');

An old question, but after some digging and a combination of answers this worked for me:

<?php $content = get_the_content();

echo strip_shortcodes($content);?>

I was only inserting galleries, which I wanted to remove and display separately. Obviously if you want to remove a specific shortcode this might not be the solution for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!