douganmo1121 2012-02-28 03:54
浏览 41

wordpress手机主题删除短代码

I have a site where the shortcodes are appearing in the mobile version of the site. I want to remove them. When I add the below code, it strips out the shortcode and also the text along with it. I want a way to simply ignore the shortcode and leave the text.

Example: "[dropcarp2]G[/dropcap2]o and get a drink" Should appear as "Go and get a drink", but on a mobile device appears as "o and get a drink"(i.e. all text between the shortcode is removed).

Can anyone help?

I have been to functions.php in the mobile theme and added the following lines of code:

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');
  • 写回答

1条回答 默认 最新

  • duanlu1793 2012-06-16 21:45
    关注

    You may need to filter 'the_content' and strip all the shortcode from there:

    EXAMPLE:

    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;
    }
    

    Give it a try

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探