All Resources

Add blog page content before posts

When using a static front page and blog page, it’s sometimes nice to show the content of the blog page itself before looping through its posts. This piece of code will pull the content from the blog page (as set by Settings > Post Page) and output it before the loop of posts.


<?php
/*
———————————————————————————-
Ouput content for blog page (Settings > Static page > posts page) page above posts
———————————————————————————-
*/
function wphandcrafted_add_blog_page_content() {
if ( is_home() ) {
$post = get_page( get_option('page_for_posts'));
echo wpautop($post->post_content);
}
}
add_action ('loop_start', 'wphandcrafted_add_blog_page_content');
?>

September 9, 2014 WordPress Development