【问题标题】:Wordpress: the_content filter kills gallery shortcodeWordpress:the_content 过滤器杀死画廊简码
【发布时间】:2012-05-28 00:10:54
【问题描述】:

我的 the_content 过滤器杀死了画廊短代码,我不知道问题出在哪里...... 我可以只添加空白的 the_content 过滤器,画廊从内容中消失,只有[gallery] 文本。我正在使用 the_content 过滤器:

function test($data){
    echo $data;
}
add_filter('the_content', 'test');

有什么建议可以解决吗?

【问题讨论】:

    标签: wordpress plugins filter shortcode


    【解决方案1】:

    您可以在 do_shortcode() 中传递修改后的内容,以在处理完内容后保持短代码功能正常工作。

    add_filter('the_content','your_function');
    function your_function($content)
    {   
        $content = get_the_content();
        $content = ;// Add your own stuff
        $content = do_shortcode($content);
    return $content;    
    }
    

    【讨论】:

      【解决方案2】:

      这是一个常见的错误,您只需要返回信息以继续应用新过滤器,因此请更改函数:

      function test($data){
          //apply here any content modification then return new content
          return $data;
      }
      add_filter('the_content', 'test');
      

      您可以通过以下方式获取更多信息:http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

      【讨论】:

      • 我的问题是 ECHO 命令,而不是 RETURN。这就是为什么它没有做我想要的。谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 2013-07-07
      相关资源
      最近更新 更多