how to Show one page's content on another page using shorcode - wordpress


Paste this in your functions.php file 
function get_post_page_content( $atts ) {
   extract( shortcode_atts( array(
    'id' => null,
    'title' => false,
   ), $atts ) );

   $the_query = new WP_Query( 'page_id='.$id );
   while ( $the_query->have_posts() ) {
    $the_query->the_post();
           if($title == true){
           the_title();
           }
           the_content();
   }
   wp_reset_postdata();

  }
  add_shortcode( 'my_content', 'get_post_page_content' );
Now  you can use the shortcode
 " [my_content id="Enter your page id number" title=Set this to true if you want to show title /] "


Share on Google Plus

About Amit

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment