Wordpress开发人员自定义背景选项

时间:2015-05-29 00:39:18

标签: php html css wordpress wordpress-theming

我在添加自定义背景选项时一直在阅读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>

由于我的主题的复杂性,这将无法工作,我需要能够更改上面的代码段,以便它将覆盖.menu-wrapper标签的默认背景,有没有办法可以更改默认的CSS选择器以定位不同的标签而不是身体?

1 个答案:

答案 0 :(得分:0)

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

我完全在这里猜测,但我认为你想要定义一个被调用的函数来返回你想要的输出。您需要调整admin-head-callback,&amp; admin-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;
}