{"id":105016,"date":"2012-12-08T09:00:24","date_gmt":"2012-12-08T14:00:24","guid":{"rendered":"http:\/\/wpmu.org\/?p=105016"},"modified":"2012-12-07T19:48:39","modified_gmt":"2012-12-08T00:48:39","slug":"insert-wordpress-page-content-anywhere-you-like-in-your-site","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/insert-wordpress-page-content-anywhere-you-like-in-your-site\/","title":{"rendered":"Insert WordPress Page Content Anywhere You Like in Your Site"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-105017\" title=\"embed\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/12\/embed.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"551\" height=\"410\" \/><br \/>\nIf you need to insert content from a Page into other places in your site, such as in a sidebar or a category page, then that\u2019s easily done with this little trick I <a href=\"http:\/\/www.scottnelle.com\/138\/load-a-page-into-a-wordpress-theme\/\" target=\"_blank\">discovered from Scott Nelle<\/a>.<\/p>\n<p>As Scott mentions, he does this for clients so that they can easily add content to a sidebar. He just creates a Page and labels it so that they know that\u2019s the Page they need to edit to change their content area in the sidebar.<\/p>\n<p>Pretty smart, if you ask me. They don\u2019t need to know where the widgets are, for example, or even what a widget is. Just tell them, \u201cEdit the \u2018Sidebar Page\u2019 if you want to change the content in this area.\u201d<br \/>\n<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>How To Do This<\/strong><\/h2>\n<p>First, you\u2019ll need to create a Page (not a Post) with the content want in it. You will then need to find the ID of the Page. If you aren\u2019t sure how to do that, <a href=\"https:\/\/wpmudev.com\/blog\/how-to-find-the-ids-of-wordpress-categories-posts-pages-and-more\/\" target=\"_blank\">here\u2019s one way<\/a>.<\/p>\n<p>Next, put the following code where you\u2019d like your Page content to show up (such as in a sidebar):<\/p>\n<pre>&lt;?php\r\n $id = ID#;\r\n $p = get_page($id);\r\n echo apply_filters('the_content', $p-&gt;post_content);\r\n ?&gt;<\/pre>\n<p>You will need to insert your actual Page ID in the spot that says ID# above. So, for example, if I find out that my page ID is 14, my code in that section will look like this:<\/p>\n<pre>$id = 14;<\/pre>\n<p>After that, you may need to do some styling, depending on your layout and how you want things to work, but that\u2019s it really. You can now go back and edit the page you created, and it will change the content wherever you\u2019ve put your code for it.<\/p>\n<h2><strong><br \/>\nTaking It a Little Further<\/strong><\/h2>\n<p>I found the code above recently when I was looking to do something similar, though my situation was just slightly more complicated. I\u2019ll go ahead and go over my situation as it may spur ideas for you to use this type of code in your own ways.<\/p>\n<p>In my situation, I needed to put <strong>different<\/strong> content into <strong>different<\/strong> category templates.<\/p>\n<p>In other words, I needed to be able to write up some editable content and images, and then insert them in a special place on my Blue Category page, for example. Then I needed to do the same thing for my Red Category, Yellow Category, and Green Category Pages.<\/p>\n<p>I\u2019ll try to represent that graphically.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-105018\" title=\"content-in-categories\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/12\/content-in-categories.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"551\" height=\"891\" \/><\/p>\n<p>&nbsp;<\/p>\n\n<p>&nbsp;<\/p>\n<h2><strong>The Solution<\/strong><\/h2>\n<p>The solution was to use the code mentioned at the beginning of the post but to also use category templates. You can learn about <a href=\"https:\/\/wpmudev.com\/blog\/how-to-create-a-unique-wordpress-category-archive-page\/\" target=\"_blank\">creating category templates here<\/a>.<\/p>\n<p>As demonstrated above, I created a Page and then got the ID for it. (Let\u2019s say the ID was 5.) This was content for my Blue Category.<\/p>\n<p>I then created a Blue Category template (category-blue.php), placed the code above into the template where I wanted the content to appear, and put my Page ID into the correct spot so it looked like this:<\/p>\n<pre>&lt;?php\r\n $id = 5;\r\n $p = get_page($id);\r\n echo apply_filters('the_content', $p-&gt;post_content);\r\n ?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>And that was it. My Blue Category was set.<\/p>\n<p>Then I moved on and made my Red Category content by creating a NEW Page. I got the ID for that (ID = 6). And then I created a Red Category template (category-red.php) and put my code in. It looked like this:<\/p>\n<pre>&lt;?php\r\n $id = 6;\r\n $p = get_page($id);\r\n echo apply_filters('the_content', $p-&gt;post_content);\r\n ?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>And on and on I went for all the different categories I wanted this for. Now, as you can see, I can easily go into my newly created Pages and update\/change the inserted content for different categories.<\/p>\n<p>If I want to change the inserted content on my Blue Category page, I just go to the Page I created for that and work in the editor, which is much easier than digging into the category templates and working with raw HTML, for example. In the editor, it&#8217;s easy to insert pretty much whatever you like \u2013 text, images, videos, etc.<\/p>\n<p>So there you go &#8212; next time you wish you had an easily editable area somewhere on your site, you might remember this little trick of pulling in Page content wherever you like.<\/p>\n\n<p>Photo: <a href=\"http:\/\/www.bigstockphoto.com\/image-296473\/stock-photo-embedment\" target=\"_blank\">Embedment<\/a> from BigStock<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Give your clients easily editable regions on their site, or get even more creative.<\/p>\n","protected":false},"author":84404,"featured_media":105017,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[],"tutorials_categories":[],"class_list":["post-105016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/105016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=105016"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/105016\/revisions"}],"predecessor-version":[{"id":216431,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/105016\/revisions\/216431"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/105017"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=105016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=105016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=105016"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=105016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}