Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active April 9, 2019 16:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srikat/7e83bdc07cd7557d4cbfeaa0851921ae to your computer and use it in GitHub Desktop.
Save srikat/7e83bdc07cd7557d4cbfeaa0851921ae to your computer and use it in GitHub Desktop.
Add Content below Title for Posts page inside div.posts-page-description in Genesis. https://sridharkatakam.com/adding-content-title-inside-div-posts-page-description-genesis/
// 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>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment