Wordpressのfunctions.phpに現在下記の2つを入れているのですが、両方のショートコードを固定ページにいれると固定ページにphpテンプレートをインクルードされずに困っています。
PCとSPで切替用のショートコードを消したらインクルードはされます。
固定ページ
[pc] PC用コンテンツ [/pc] [sp] SP用コンテンツ [myphp file='kanrenlink'][myphp file='bnrlink'] [/sp]
functions.php
固定ページをPCとSPで表示切替用
//PCとスマホの分岐用ショートコード function contents_for_pc( $atts, $content = null ) { if(wp_is_mobile()) { return ''; } else { return '' . $content . ''; } } function contents_for_sp( $atts, $content = null ) { if(wp_is_mobile()) { return '' . $content . ''; } else { return ''; } } add_shortcode('pc', 'contents_for_pc'); add_shortcode('sp', 'contents_for_sp');
固定ページにphpテンプレートをインクルードする用
//パーツファイルインクルード設定 function Include_my_php($params = array()) { extract(shortcode_atts(array( 'file' => 'default' ), $params)); ob_start(); include(get_theme_root() . '/' . get_template() . "/$file.php"); return ob_get_clean(); } add_shortcode('myphp', 'Include_my_php');
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。