【问题标题】:Wordpress Developer Custom Background OptionsWordPress 开发人员自定义背景选项
【发布时间】:2015-08-11 17:10:16
【问题描述】:

我一直在阅读关于添加自定义背景选项的 WordPress 法典,就像在这个例子中一样

$defaults = array(
    'default-color'          => '',
    'default-image'          => '',
    'default-repeat'         => '',
    'default-position-x'     => '',
    'default-attachment'     => '',
    'wp-head-callback'       => '_custom_background_cb',
    'admin-head-callback'    => '',
    'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $defaults );

生成的输出如下所示:

<style type="text/css" id="custom-background-css">
body.custom-background { background-color: #bdd96e; }
</style>

由于我的主题的复杂性,这将不起作用,我需要能够更改上面的 sn-p 以便它将覆盖 .menu-wrapper 标签的默认背景,有什么方法可以更改默认 CSS 选择器以不同的标签而不是正文为目标?

【问题讨论】:

    标签: php html css wordpress wordpress-theming


    【解决方案1】:

    回调函数_custom_background_cb是什么?那是核心WP的一部分吗?

    我在这里完全猜测,但我认为您需要定义一个函数,该函数被调用以返回您想要的输出。您还需要针对admin-head-callbackadmin-preview-callback 进行调整。

    尝试这样的事情,但您可能需要对回调参数进行一些研究。

    $defaults = array(
    //  ...
      'wp-head-callback' => 'my_custom_function',
    //  ...
    
    );
    add_theme_support( 'custom-background', $defaults );
    
    function my_custom_function()
    {
        $html =  "<style type="text/css" id="custom-background-css">";
        $html += "   #my-selector { background-color: #bdd96e; }";
        $html += "</style>";
        return $html;
    }
    

    【讨论】:

    • 谢谢,帮了大忙! c:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 2018-09-18
    相关资源
    最近更新 更多