Adding Content below Title inside div.posts-page-description in Genesis

Posted on

The Genesis wonder woman, Robin Cornett has a great post on adding the page title and an intro text (page content) on Posts page in Genesis.

Here’s a slightly modified version of the same.

Add the following in child theme’s functions.php:

// Bring back the missing editor for Posts page
add_action( 'edit_form_after_title', 'rgc_posts_page_edit_form' );
function rgc_posts_page_edit_form( $post ) {

$posts_page = get_option( 'page_for_posts' );

if ( $posts_page === $post->ID ) {
add_post_type_support( 'page', 'editor' );
}

}

remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' );
add_action( 'genesis_before_loop', 'sk_do_posts_page_heading' );
/**
* Add custom headline and page content to assigned posts page.
*
* If we're not on a posts page, then nothing extra is displayed.
*
* @since 2.2.1
*
* @return null Return early if `headings` is not enabled for Genesis accessibility, there is no
* page for posts assigned, this is not the home (posts) page, or this is not the page found at `/`.
*/
function sk_do_posts_page_heading() {

if ( ! genesis_a11y( 'headings' ) ) {
return;
}

$posts_page = get_option( 'page_for_posts' );

if ( is_null( $posts_page ) ) {
return;
}

if ( ! is_home() || genesis_is_root_page() ) {
return;
}

$title = get_post( $posts_page )->post_title;

$content = get_post( $posts_page )->post_content;

$title_output = $content_output = '';

if ( $title ) {
$title_output = sprintf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), get_the_title( $posts_page ) );
}

if ( $content ) {
$content_output = wpautop( $content );
}

if ( $title || $content ) {
printf( '<div %s>', genesis_attr( 'posts-page-description' ) );
if ( $title ) {
printf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), get_the_title( $posts_page ) );
}
echo '<div class="posts-page-intro">'. $content_output .'</div>';
echo '</div>';
}

}

This will bring back the missing WP editor for the Posts page (set at Settings > Reading) and display its title (if present) and its content (if present) inside the Posts Page Description.