[英]Wordpress Developer Custom Background Options
我一直在阅读有关添加自定义背景选项的WordPress Codex,如本例所示
$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选择器更改为target一个不同的标签而不是身体?
回调函数_custom_background_cb
什么? 那是核心工作程序的一部分吗?
我在这里完全是猜测,但我想您将需要定义一个函数,该函数被调用以返回所需的输出。 您还需要针对admin-head-callback
和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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.