2

I have set my WP site to use a static home page. I created a file in the root of the theme directory called front-page.php and this template is called correctly. I cannot seem to display the content of the home page in my template. I have tried get_the_content, the_content and the post_content object. What else can I do to get the content of the home page?

<?php

get_header();

$page = get_posts( array( 'name' => '' ) ); //here, i have also tried 'home', 'front-page', and 'page-home'
if ( $page )
{
    echo $page[0]->post_content;
}

get_footer(); ?>

I have also tried...

<?php

get_header();

get_the_content();

get_footer();

?>
6

alternative to using the default loop in the front-page.php template:

if( have_posts() ) {
  while( have_posts() ) {
  the_post();
    the_content();
  }
}

you could try using:

if( get_option( 'page_on_front' ) ) {
  echo apply_filters( 'the_content', get_post( get_option( 'page_on_front' ) )->post_content );
}

https://codex.wordpress.org/Option_Reference

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.