WordPress的从内容中删除短代码

WordPress的从内容中删除短代码

本文介绍了WordPress的从内容中删除短代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行 the_content()之前,是否可以从内容中删除图库简码?我搜索了codex,发现 remove_shortcode($ tag),但是它们没有显示任何示例。

/ p>

  function remove_gallery($ content){
$ content。= remove_shortcode('[gallery]');
返回$ content;
}
add_filter('the_content','remove_gallery',6);

不起作用..



更新:



我可以使用下面的代码取消注册短代码,但它也会删除内容

 函数remove_gallery($ content){
return remove_shortcode('gallery',$ content);
}
add_filter('the_content','remove_gallery',6);


解决方案

奇怪。 remove_shortcode()不需要第二个参数。

您将返回remove_shortcode函数的真或假返回值,而不是移除短码的内容。





  remove_shortcode( '画廊'); 
返回$ content;

或者直接放入

  remove_shortcode('gallery'); 

在您的functions.php文件中。以前的海报建议包括[]的,我猜是错误的。

Is it possible to remove the gallery shortcode from the content before when the_content() is executed? I searched codex and found remove_shortcode( $tag ) but they show no examples.

I tried adding to functions

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

It doesnt work..

Update:

I was able to unregister the shortcode using the code below, but it also removes the content

function remove_gallery($content) {
    return remove_shortcode('gallery', $content);
}
add_filter( 'the_content', 'remove_gallery', 6);
解决方案

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.

这篇关于WordPress的从内容中删除短代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:17