How to embed a WordPress page inside another page

Sometimes you will create a template or a page that will require you to embed the content from another page. There are a couple of plugins that will help you do this, like Improved Include Page but I don’t like to install plugins just because they exist.

The code

<?php $recent = new WP_Query('page_id=ID'); while($recent->have_posts()) : $recent->the_post();?>
       <h2><?php the_title(); ?><h2/h>
       <?php the_content(); ??>
<?php php endwhile; ?>

To make it work, you will need to replace ID with the page that you want to embed. If you are working on another loop on the same page, don’t forget to reset the query by using wp_reset_query();