【问题标题】:How to add a body class如何添加body类
【发布时间】:2012-09-23 00:41:37
【问题描述】:

我的functions.php 文件中有以下代码。我想要做的是在我的简码 [模板] 中再添加一个属性(比方说 - “extraclass”)。属性的值应该是额外类的名称,我希望我的代码将这个类添加到 body 标记中。 add_filter 函数我知道,我尝试过使用但没有成功。

function templatefn($atts, $content = null) {
    extract(shortcode_atts(array(
        "content" => ""
    ), $atts));

    ob_start();
    get_template_part('content', $content);
    $ret = ob_get_contents();  
    ob_end_clean();  
    return $ret;   
}
add_shortcode('template', 'templatefn');

提前致谢!

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    在您的模板中,如果您使用函数 body_class() 为 body 元素提供不同的 css 类(基于您当前的条件样式页面),那么您应该能够 filter this using the examples listed 来实现您的结果。

    【讨论】:

    • OP说add_filter不可用,难道不能用tag来实现吗?
    猜你喜欢
    • 1970-01-01
    • 2014-07-28
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2017-09-18
    • 2020-01-22
    相关资源
    最近更新 更多