Working with WordPress for quite a while, I had this idea of using multiple pages as “storage” for some of my template file’s contents particularly the home page. For example in a home page with custom layout the first block of content is from a different page and the second one is from another instead of just hard coding the content in the template file itself. By using Posts (or Pages) as content sources, editing them is a breeze and you don’t have to reopen the template files every time you do so.
To do this I used an amazing (and underrated?) plugin called Post Content Shortcodes by Curtiss Grymala. “This plugin adds two shortcodes that allow you to display either the content of a post or a list of posts within the content area of a post. This plugin should be fully compatible with all post types, as it simply uses the
get_posts() WordPress functions.” This plugin has many useful features such as displaying post content, displaying post lists, and pulling posts from another blog in a multi-site setup. In this tutorial, we will only be delving in on how to use Pages as content sources for other Pages, template files, and/or Posts.
Step 1: Install the Post Content Shortcodes plugin in your WordPress installation.
You can find the plugin’s WordPress page here:
Step 2: Create a Page (or post if you prefer) that will serve as the source of your content.
A little thing to consider is that the page you created will only serve as storage and not as a stand-alone page. You might want to block this particular page from search engines. This is easily achieved by using another plugin called Robots Meta by Joost de Valk. After installing the plugin, a box will appear at the sidebar when editing a page:
Choose noindex, nofollow to block this particular page from search engines. Only the URL of this page will be blocked from search engines and not the page that its content will be displayed in.
Step 3: Use the shortcode to add it in another Page, Post, or template file.
If you are trying to add the content to a template file such as your home page you can use the do_shortcode() WordPress function to execute the shortcode:
echo do_shortcode('[post-content id=2095]');
As you might have guessed, the argument id is the Post ID of the Post or Page (or any other post type for that matter) that you want to display. You can get the Post ID by checking the URL when you edit it. For instance:
The Post ID is the one shown highlighted.
But if you want to display another post’s or page’s content within other posts or pages, simply enter in the WordPress text editor the shortcode:
That concludes this tutorial! If you have any comments or suggestions to this method I’m more than happy to hear them in the section below. Thanks for reading!