投稿・固定ページ内にPHPファイルをインクルード(挿入/実行)させる

function.phpにこれを入れる

<?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');
//ここまで

?>

これを固定ページに

[myphp file='papo']

ファイルをまとめたいとき

include(get_theme_root() . '/' . get_template() . "/tama/$file.php");

子テーマ化してるとき

function Include_my_php($params = array()) {
extract(shortcode_atts(array(
'file' => 'default'
), $params));
ob_start();
get_template_part("/myphpfiles/$file");
return ob_get_clean();
}

add_shortcode('myphp', 'Include_my_php');

検索用文字列:ショートコード