【问题标题】:can't get apply_filter to work in wordpress thematic无法让 apply_filter 在 wordpress 主题中工作
【发布时间】:2014-11-16 05:38:34
【问题描述】:

我正在学习使用主题框架在 wordpress 中创建模板

在我找到的头文件中:

 // Filter provided for altering output of the header opening element
    echo ( apply_filters( 'thematic_open_header',  '<div id="header">' ) );

   // Action hook creating the theme header
   thematic_header();

    echo ( apply_filters( 'thematic_close_header', '</div><!-- #header-->' ) );

我想在上面创建的 div id="header".../div 周围添加一个包装 div 元素

我尝试像这样编辑 apply_filter 行:

echo ( apply_filters( 'thematic_open_header',  '<div id="headerWrapper"><div id="header">' ) );

但它不起作用,只是打印输出 div id="header"

我怎样才能让它创建我想要的 html?

谢谢

【问题讨论】:

    标签: wordpress filter


    【解决方案1】:

    过滤器用于functions.php 或类似这样的插件中:

    add_filter( 'thematic_open_header', function(){
        return '<div id="headerWrapper"><div id="header">';
    });
    

    apply_filtersdo_action 之间的基本区别在于第一个过滤 一些值并返回一些东西,而add_action 将用于对发送或输出的参数做任何你想做的事情浏览器的东西。

    一些感兴趣的文章:[1][2][3][4]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多