[英]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.