2017-09-21 35 views
0

在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'); 

但它是行不通的。請讓我知道是否有其他方法。

+0

你需要去學習一些基本的PHP - 在這種情況下,有關變量的作用域。 http://php.net/manual/en/language.variables.scope.php你的函數中沒有$ options。另外,在這種情況下,去配置您的PHP和/或WordPress以向您顯示適當的錯誤消息。 – CBroe

+0

你也可以從你的框架粘貼選項字段嗎? – Gazi

+0

@Gazi: - [themecss] => theme_style1.css –

回答

0
function theme_script_enqueue(){ 
$options = get_option('admin_theme_option'); 
if($options != "") { 
$mystyle = 'custom_style'; //css file name 
} else { 
$mystyle = 'default_style'; // your default css file name 
} 
wp_enqueue_style('customestyle', get_bloginfo('template_url') . '/'.$mystyle.'.css'); 
} 
add_action('wp_head','theme_script_enqueue'); 

,你必須得到$options = get_option('admin_theme_option');進入功能

+0

感謝兄弟(thumbsup) –

+0

謝謝我再次改變我的答案有wp_head,而不是如果你想你可以使用wp_footer移動到頁腳 – Gazi

相關問題