Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save josephhinson/5671163 to your computer and use it in GitHub Desktop.

Select an option

Save josephhinson/5671163 to your computer and use it in GitHub Desktop.
So, you want to pull content from one page into another...maybe you have an "upcoming events" section that you want to be its own page, yet you also want to show on another page. This shortcode will help you do that. Put this code in your functions.php file.
<?php
// [page name="contact"]
function page_content($atts) {
extract(shortcode_atts(array(
'name' => ''
), $atts));
$return = '';
$args=array(
'name' => $name,
'post_type' => 'page',
'post_status' => 'publish',
'numberposts' => 1
);
$thepages = get_posts($args);
foreach ($thepages as $thepage) {
$return .= apply_filters('the_content',$thepage->post_content);
}
return $return;
}
add_shortcode("page", "page_content");
// end shortcode
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment