【问题标题】:wordpress mobile theme remove shortcodeswordpress 移动主题删除简码
【发布时间】:2012-03-17 13:58:47
【问题描述】:

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

示例:“[dropcarp2]G[/dropcap2]o and get a drink”应该显示为“Go and get a drink”,但在移动设备上显示为“o and get a 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');

【问题讨论】:

    标签: php wordpress mobile themes wordpress-theming


    【解决方案1】:

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

    试试看

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 2019-07-17
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多