Recently one of our users asked if it was possible to add content from a WordPress page into another post or page. In this article, we will show you how to insert content from one WordPress page to another post, page, or any custom post types.
First thing you need to do is install and activate the Insert Pages plugin. Upon activation simply go to Posts Β» Add New to see it in action.
If you use visual editor, then you will notice a new button labeled βInsert Pageβ in the menu.
Clicking on it will bring up a popup where you can select the page, post, or custom post type you want to add.
You can choose how you would like to insert the post/page by clicking on the Options. By default you can add title, content, link, or choose a custom template. We will explain custom templates later in this article.
After choosing the post/page click on the Insert Page button. The plugin will add the shortcode required to display your selected post/page.
If you use the text editor to write your posts, then you can manually enter the shortcode. The shortcode parameters are quite simple.
[insert page='page-slug|ID' display='title|link|content|all|custom-template.php']
The page parameter for the shortcode accepts page-slug or ID. Please note that by page slug, it doesnβt mean that you can only enter pages. You can add any post or custom post typeβs slug as well.
You can also use post id. Here is a quick guide on how to find post id in WordPress.
[insert page='author-syed-balkhi' display='content']
[insert page='128' display='content']
[insert page='128' display='all']
[insert page='128' display='custom-author.php']
Adding Custom Post Types into Posts
Using WordPress you can add any type of content by creating post types for different content types. Checkout our guides on when do you need a custom post type and how to create a custom post type in WordPress.
Insert Pages allows you to add your custom post types into posts and pages. For example, you can create a custom post type for image galleries and then use Insert Pages to add those galleries into your posts or pages.
Similarly, you can create custom post types for videos, portfolio, client testimonials, etc. to add into your pages or posts.
Using Custom Templates to Display Inserted Pages
Insert Pages allows you to display title, link, content, or all fields for inserted pages. However some users may still need to tweak the display to meet their own needs. This can be achieved by using custom templates.
All you need to do is create a blank php file and upload it to your theme directory. You can name the file anything you want. For example, custom-author.php.
This custom template works exactly like any other content template files in your theme. Here is sample template file that we created to display author pages.
1 2 3 4 5 6 7 8 9 10 | <?php the_post(); ?> <h3 class = "author-name" ><?php the_title(); ?></h3> <?php if ( has_post_thumbnail() ) : ?> <div class = "author-thumbnail" > <?php the_post_thumbnail(); ?> </div> <?php endif ; ?> <div class = "author-bio" > <?php the_content() ?> </div> |
You can use custom CSS classes in your template file and then style them in your themeβs stylesheet. We used this to style the display of author pages.
1 2 3 4 5 6 7 8 9 10 11 | h 3 .author-name { font-size : 16px ; } .author-thumbnail { float : left ; padding : 10px ; } .author-bio { font-style : italic ; font-family : Lora, Georgia, Serif ; } |
This is how the end result looked on our dummy site:
We hope this article helped you add content from one WordPress page/post to another.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Google+.