Created
August 13, 2014 18:51
-
-
Save ingozoell/fb468a98bcd773b4398f to your computer and use it in GitHub Desktop.
WordPress shortcode to insert content of another page
http://alex.leonard.ie/2010/09/09/wordpress-shortcode-to-insert-content-of-another-page/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a shortcode to insert content of a page of specified ID | |
* | |
* @param array attributes of shortcode | |
* @return string $output Content of page specified, if no page id specified output = null | |
*/ | |
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('pa_insert', 'pa_insertPage'); | |
/* USAGE | |
* <?php echo do_shortcode('[pa_insert page="1228"]');?> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment