Get all page content and display in header

Created a page and wants to display all content in header.php , but it doesn't display anything.

below:

$page = get_page_by_title( 'TEST' );
$content = apply_filters('the_content', $page->post_content);
echo $content;

      

Is there any other way to do this?

+3


source to share


2 answers


Try this (just replace 123 with your page id):



$page_object = get_page( 123 );
$my_content=$page_object->post_content;
echo do_shortcode( $my_content );

      

+1


source


Use the following code to get:

$page = get_page_by_title('TEST', OBJECT, 'page');
echo $page->post_content;

      

Use the following code if the page has a shortcode and text added to the page on the Contact page:

$page = get_page_by_title('Contact', OBJECT, 'page');
$page->post_content;

// will match square brackets

if (preg_match('^\[(.*?)\]^', $page->post_content))
{
    echo do_shortcode($page->post_content);

}else{

    echo $page->post_content;

}

      



Use if you have text as well as shortcode on the page replace 226 with your page id;

$id=226;
$post = get_page($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;

      

Read: https://codex.wordpress.org/Function_Reference/get_page_by_title

+1


source







All Articles