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

Wordpress Developer Custom Background Options

我一直在阅读有关添加自定义背景选项的 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 选择器定位不同的标签而不是 body?

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

我完全是在猜测,但我认为您需要定义一个函数,该函数被调用以 return 您想要的输出。您还需要针对 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;
}