PHPファイルを固定ページに入れるにはショートコードを使うと便利!!
まずはfunctions.phpにショートコードをつ空けるようにする記述をする。
[functions.php]
//ショートコードを使ったphpファイルの呼び出し方法
function my_php_Include($params = array()) {
extract(shortcode_atts(array('file' => 'default'), $params));
ob_start();
include(get_theme_root() . '/' . get_template() . "/category/$file.php"); //フォルダを指定することも出来る!
return ob_get_clean();
}
add_shortcode('myphp', 'my_php_Include');
※フォルダを指定しない場合はこちら
include(get_theme_root() . '/' . get_template() . "/$file.php");
◎ショートコードの呼び出し
[myphp file='couce01']
[functions.php]
//ショートコードを使ったphpファイルの呼び出し方法
function Include_my_php($params = array()) {
extract(shortcode_atts(array(
'file' => 'default'
), $params));
ob_start();
get_template_part("/code/$file");
return ob_get_clean();
}
add_shortcode('myphp', 'Include_my_php');
<?php echo do_shortcode('[instagram-feed]'); ?>