我有一个网站,其中的短代码出现在该网站的移动版本中。我想把它们去掉。当我添加下面的代码时,它会去掉短代码和文本。我想要一种简单地忽略短代码并留下文本的方法。
示例:"[dropcarp2]G[/dropcap2]o and get a drink"应显示为"Go and get a brink",但在移动设备上显示为"o and get an drink"(即,删除快捷代码之间的所有文本)。
有人能帮忙吗?
我已经访问了移动主题中的functions.php,并添加了以下代码行:
function my_shortcode_handler( $atts, $content=null, $code="" )
{
return '';
}
//override the 'dropcap2' shortcode
add_shortcode('dropcap2', '__return_false');
add_shortcode('two_thirds', '__return_false');
add_shortcode('one_third', '__return_false');
add_shortcode('divider_1', '__return_false');
add_shortcode('services', '__return_false');
add_shortcode('one_third_last', '__return_false');
您可能需要筛选"the_content"并从中删除所有短代码:
示例:
add_filter( 'the_content', 'str_replace_shortcode', 1 );
function str_replace_shortcode( $content ) {
$content = str_replace(
array( '[dropcarp2]', '[/dropcarp2]' ), // Put everything in the array
'', $content );
return $content;
}
试试