Add a specific page or post content in another post or page

Following this discussion in the Customizr theme support forum, here’s a simple piece of code that will allow you to add any post or page before your post or page content in the Customizr WordPress theme.

The following snippet will add the content on your front page and before the featured pages.

You can change the condition ( ! tc__f(‘is_home’) ) and the hook to target a new context and a new location in any pages/posts/archives.

 

function display_content_before(){
   if ( !tc__f('__is_home') )
        return;
    //gets the page object from your database
    $mypage = get_post(205); //<= set the id of the page or post you want to insert
    ?>
    <div class="row-fluid">
	    <div id="content" class="article-container span12">
	    	<article>
		    	<div class="entry-content">
		        	<?php echo apply_filters('the_content' , $mypage -> post_content ); ?>
		    	</div>
		    </article>
	    </div>
	</div>
    <?php
}
//adds the page before featured pages. Note the priority set to 0 in the action declaration => will tell WordPress to add the action before any other (featured pages have a priority of 10 on this very same hook)
add_action  ( '__before_main_container', 'display_content_before', 0 );

Additional resources :

16 thoughts on “Add a specific page or post content in another post or page”

Comments are closed.