インターネットからのコード サンプルを使用して、特定のページを返すショートコードを作成しました。ただし、ショートコードはレンダリングされていないようですが、ショートコードのテキストがそのまま表示されます。関数は 内で定義されていfunctions.php
ます。
コードは次のとおりです。
/* Code taken from:
* http://alex.leonard.ie/2010/09/09/wordpress-shortcode-to-insert-content-of-another-page/
*/
function pa_insertPage($atts, $content = null) {
// Default output if no pageid given
$output = NULL;
// extract atts and assign to array
extract(shortcode_atts(array(
"page" => '' // default value could be placed here
), $atts));
// if a page id is specified, then run query
if (!empty($page)) {
$pageContent = new WP_query();
$pageContent->query(array('page_id' => $page));
while ($pageContent->have_posts()) : $pageContent->the_post();
// assign the content to $output
$output = get_the_content();
endwhile;
}
return $output;
}
add_shortcode('insert_page', 'pa_insertPage');