WordPress Include Page or Post within another Page or Post via Templates

/ Published in: PHP
Save to your folder(s)

By adding this function to ones functions.php and then a call in ones page.php, single.php, home.php, index.php or custom template file. You can include on page within another.

Copy this code and paste it in your HTML
  1. //Add to functions.php
  2. function show_post($path) {
  3. $post = get_page_by_path($path);
  4. $content = apply_filters('the_content', $post->post_content);
  5. echo $content;
  6. }
  8. //add to your page/post/template file
  9. <?php show_post('about'); // Shows the content of the "About" page. ?>
  10. <?php show_post('category/postname'); // Shows content of a Post page. ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.