我正在设置一个新的页面模板,该模板在一个列中显示一个页面的图库(如果它有一个),包含在一个独立的div中,浮动到右边,所有其他内容都向左浮动。我可以通过get_post_gallery()回显右边的图片库,现在我想从the_content()中去掉该图库。
我本质上希望定位的是一个与strip_shortcodes()完全相同的函数,但是用于特定的短代码。类似于strip_shortcode(“图片库”)或strip_shortcode(“图片库”,content())。有人为Wordpress写了这样一个函数吗?
Remove_shortcode(“图库”)工作条--它在运行时会将该死的短代码文本留在后面。我可以通过CSS隐藏图库,也可以通过jQuery删除它,但我希望它一开始就不被输出。
发布于 2013-12-27 07:32:49
若要删除短代码或特定的短代码列表,可以使用此代码。
global $remove_shortcode;
/**
* Strips and Removes shortcode if exists
* @global int $remove_shortcode
* @param type $shortcodes comma seprated string, array of shortcodes
* @return content || excerpt
*/
function dot1_strip_shortcode( $shortcodes ){
global $remove_shortcode;
if(empty($shortcodes)) return;
if(!is_array($shortcodes)){
$shortcodes = explode(',', $shortcodes);
}
foreach( $shortcodes as $shortcode ){
$shortcode = trim($shortcode);
if( shortcode_exists($shortcode) ){
remove_shortcode($shortcode);
}
$remove_shortcode[$shortcode] = 1;
}
add_filter( 'the_excerpt', 'strip_shortcode' );
add_filter( 'the_content', 'strip_shortcode' );
}
function strip_shortcode( $content) {
global $shortcode_tags, $remove_shortcode;
$stack = $shortcode_tags;
$shortcode_tags = $remove_shortcode;
$content = strip_shortcodes($content);
$shortcode_tags = $stack;
return $content;
}
dot1_strip_shortcode( 'Test' );
dot1_strip_shortcode( 'Test, new_shortcode' );
dot1_strip_shortcode( array('Test', 'new_shortcode') );接受单个、逗号分隔的短代码字符串或短代码数组。
https://stackoverflow.com/questions/20023106
复制相似问题