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');
しかし、それは動作していません。他の方法があれば私に知らせてください。
に
$options = get_option('admin_theme_option');
を取得する必要があります - この場合には、変数のスコープについて。 http://php.net/manual/en/language.variables.scope.phpあなたの関数内には$ optionsはありません。また、そのような場合に適切なエラーメッセージを表示するようにPHPやWordPressを設定してください。 – CBroeフレームワークのオプションフィールドも貼り付けることができますか? – Gazi
@Gazi: - [themecss] => theme_style1.css –