advanced custom fieldsをfunctions.phpで条件分岐で出力
-
こんにちは
■advanced custom fieldsのSelectを使いWidgetに出力させて、functions.phpで条件分岐をしたいのですが、思うように動いてくれません。
作ったソースは以下です。
// functions.php
function acf_scripts() { $ctm = get_field('fontfamily', 'widget_' . $args['widget_id']); if( ($ctm == 'body-roboto') ){ echo "Can be obtained"; } else { echo "can not get"; } } add_action('wp_head', 'acf_scripts');
ACFのフィールド名が fontfamily でSelectで body-roboto を選択でCan be obtainedをhead部分に出力する仕組みを作りたいのですが、can not getが出力されます。
■試した事
以下のページを参照しましたが取得できませんでした。
https://www.advancedcustomfields.com/resources/select/<?php
if( get_field(‘color’) == ‘red’ ) {
// Do something.
}
?>
上記の方法ではindex.phpなどのテンプレートで条件分岐はできますが、function.phpでは動いてくれません。よろしくお願いいたします。
- このトピックはが4年前に変更しました。
- このトピックはが4年前に変更しました。
- このトピックはが4年前に変更しました。
- このトピックはが4年前に変更しました。
- このトピックはが4年前に変更しました。
- このトピックはが4年前に変更しました。
ヘルプの必要なページ: [リンクを見るにはログイン]
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
- トピック「advanced custom fieldsをfunctions.phpで条件分岐で出力」には新たに返信することはできません。