How to Display Post or Page Content Anywhere in WordPress

  • Sharebar

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_post() and 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:

http://wordpress.org/extend/plugins/post-content-shortcodes/

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:

[post-content id=2095]

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!

About maca

Hello, my name is Karlo Macariola. I once dreamed to be a painter or an animator but when I typed my first line of code I immediately fell in love with programming. Today my passions are with web development and web design though sometimes I still withdraw to my first love which is drawing. DeviantArt | Twitter | Facebook
This entry was posted in Web Development & Design and tagged , . Bookmark the permalink.

2 Responses to How to Display Post or Page Content Anywhere in WordPress

  1. Daniel Koepf says:

    Very interesting approach! I never even thought of that. Could be useful in a coming project maybe. Thanks for posting!

  2. Jeff Reinhardt says:

    I am trying to use your shortcode in a home page template. The plugin is activated and I’m using the code as demonstrated on your page but I can’t get it to work:

    Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>