2012-02-28 52 views
0

我有一个网站,其中的简码出现在网站的移动版本。我想删除它们。当我添加下面的代码时,它会删除短代码以及文本。我想要一种简单地忽略短代码并离开文本的方式。wordpress移动主题删除简码

例如:“[dropcarp2] G [/ dropcap2] o并喝一杯”应该出现为“去喝一杯”,但在移动设备上显示为“o并喝一杯”(即所有文字之间的短码被删除)。

任何人都可以帮忙吗?

我一直在移动主题的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'); 

回答

0

您可能需要过滤“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; 
} 

试试看