Display the title of the page above the post excerpts


Hey Fabio,

Because it is the home page which displays the list of posts, the_title() grabs the first post title in the query. The work around is the get the id of the home page assigned in your Settings->Reading and fetch the title using that id. Here is the snippet example:

add_action( 'beans_header_after_markup', 'example_view_add_title' );

function example_view_add_title() {
 $title = get_the_title( get_option( 'page_for_posts' ) );

 ?>
  <div class="uk-container uk-container-center">
    <h1 class="uk-text-center"><?php echo esc_html( $title ); ?></h1>
 </div>
  <?php

}

Happy coding,


It works perfectly, fantastic! Always thanks Thierry.

Write a reply

Login or register to write a reply, it's free!