在WordPress管理中,我創建了一個選項來爲前端選擇custome樣式表。我必須從管理選項enqueue_style。我喜歡下面的東西...如何在WordPress中使用get_option排除樣式
$options = get_option('admin_theme_option');
function theme_script_enqueue(){
if($options){
wp_enqueue_style('customestyle', get_template_directory_uri() . '/assets/css/'.$options['themecss'],array(),'1.0.0','all');
}else{
wp_enqueue_style('customestyle', get_template_directory_uri() . '/assets/css/default.css',array(),'1.0.0','all');
}
add_action('wp_enqueue_scripts','theme_script_enqueue');
但它是行不通的。請讓我知道是否有其他方法。
你需要去學習一些基本的PHP - 在這種情況下,有關變量的作用域。 http://php.net/manual/en/language.variables.scope.php你的函數中沒有$ options。另外,在這種情況下,去配置您的PHP和/或WordPress以向您顯示適當的錯誤消息。 – CBroe
你也可以從你的框架粘貼選項字段嗎? – Gazi
@Gazi: - [themecss] => theme_style1.css –