2017-07-19 120 views
0

我正在工作一個新的WordPress主題。 正常情況下,主題可以選擇在定製器中設置徽標。 這是行得通的。WordPress的默認標誌

但是,我想讓主題自動設置DEFAULT徽標。 如果用戶未在定製器中定義徽標,則默認徽標將自動顯示。 我有一個名爲logo.jpg的圖像在文件夾中調用img在主題根目錄中。

我使用這個代碼來設置默認的標誌,但它不工作:

add_filter('get_custom_logo',function($html){ 
if(empty($html)) { 
    $html = '<img src = get_template_uri() . "/img/logo.jpg" >'; 
} 
return $html; 
}); 

任何想法?這是我的語法與「混合和「?

謝謝!

+0

Yes.'「」;' – colburton

回答

0

你必須在字符串連接錯誤。

PS請不要在過濾器中使用匿名函數,因爲它不是可以刪除或兒童的主題改變該過濾器例如

add_filter('get_custom_logo', 'apply_default_logo'); 
function apply_default_logo($html){ 
    if(empty($html)) { 
     $html = '<img src="' . get_template_directory_uri() . '"/img/logo.jpg">'; 
    } 
    return $html; 
} 
+0

尼克您好,感謝回來了 - 非常感謝您提供沒有顯示任何錯誤代碼,但也沒有設置默認的標誌oughts?謝謝, – AlanisTuring

+0

@AlanisTuring,功能名稱爲'get_template_uri()'時出現錯誤,您能否嘗試用'get_template_directory_uri()'替換它? –

+0

是的,我試過,但沒有運氣 - 默認的標誌仍然沒有顯示。 – AlanisTuring