Load the Content of a Worpress Page in PHP Code

Sometimes its necessary to load the content of a wordpress page or post, directly into a php file to display it wherever you want on your website.
For this, hook the pages and posts via id or name.

Load the content of a wordpress page in php

In your php file add one of the following steps to display the content of a wordpress page.

Load by name:

<?php
$page = get_page_by_title( 'Members' );
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>

Load by id (replace the “1” with your page id):

<?php
$page = get_page(1);
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>

Load the content of a wordpress post in php

Load by id (replace the “1” with your post id):

<?php
$post = get_post(1);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>

Hope it helped 🙂
– Kev

Leave a Reply

avatar
wpDiscuz