2015-05-29 52 views
1

我一直在閱讀上在這個例子中添加自定義背景選項,像WordPress的抄本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>

這是行不通的,因爲我的主題很複雜,我需要能夠更改上面的代碼片段,以便它w虐待覆蓋.menu包裝標籤的默認背景,是否有一種方法,我可以更改默認的CSS選擇器,以目標不同的標籤,而不是正文?

回答

0

什麼是回調函數_custom_background_cb?核心WP的那部分?

我在這裏完全猜測,但我想你會想定義一個被調用的函數來返回你想要的輸出。您還需要調整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; 
} 
+0

謝謝,這幫了很多! C: – colbyn