2017-09-21 2 views
0

WordPressの管理者で、フロントエンド用のカスタムスタイルシートを選択するオプションを作成しました。私はadminオプションから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

$options = get_option('admin_theme_option');を取得する必要があります - この場合には、変数のスコープについて。 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'); 

あなたは、いくつかのPHPの基礎を学ぶ行く必要機能

+0

ありがとうbro(thumbsup) –

+0

おかげでwp_footerを使用して、フッター – Gazi

関連する問題