WordPress get page content by id from other page or posts

In WordPress get page content by id is mainly used to get the content outside of the page calling by URL

Like as if you want to call the content of the about in home page or in the footer in case of WordPress theme development

Now code for the WordPress get page content by id step by step

  • First, you need to get the page id better to take it in a variable like $id=47;
  • Second, get all the page or post content in a variable passing by the page id like $post = get_page($id);
  • Finally, print or echo the page content like echo $post->post_content;

Now the sample code is given below:

<?php $id=47; $post = get_page($id); echo $post->post_content;  ?>

In this post, you have learned how to get WordPress to get page content by id

Please provide your comment to make the site better and more useful.

Thanks for reading

Share The Post On -

Add a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.