Created
September 2, 2017 18:00
-
-
Save carasmo/35fe7daec07eeed645a9d4554d0de246 to your computer and use it in GitHub Desktop.
Add intro text on blog posts page or a page using the blog template in Genesis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//don't add again | |
add_action( 'edit_form_after_title', 'your_prefix_posts_page_edit_form' ); | |
/** | |
* Add Editor Back on Posts Page | |
* @thanks https://robincornett.com/posts-page/ | |
*/ | |
function your_prefix_posts_page_edit_form( $post ) { | |
$posts_page = get_option( 'page_for_posts' ); | |
if ( $posts_page === $post->ID ) : | |
add_post_type_support( 'page', 'editor' ); | |
endif; | |
} | |
add_action( 'genesis_before_loop', 'your_prefix_blog_page_or_blog_template_intro_text' ); | |
/** | |
* Add Intro Text entered in the page editor on the: | |
* - 1st page of Blog posts page (if it's not the front page) | |
* - 1st page of Blog Template page (a page using the Genesis blog template) | |
* | |
* uses `the_content` filter so you can add shortcodes, videos (embeds), etc., | |
* | |
* Does not work if you show latest posts on home page | |
* since there is no page to get content from. | |
* | |
* @thanks and modified: https://robincornett.com/posts-page/ | |
*/ | |
function your_prefix_blog_page_or_blog_template_intro_text() { | |
if ( is_front_page() ) return; //* exit if front page | |
global $post; | |
$posts_page = get_option( 'page_for_posts' ); | |
$content = ''; | |
if ( is_home() && ! is_paged() ) : | |
$content = get_post( $posts_page )->post_content; | |
endif; // blog page | |
if ( is_page_template( 'page_blog.php' ) && ! is_paged() ) : | |
$content = $post->post_content; | |
endif; // page blog template | |
if ( $content != '' ) : | |
$content = apply_filters( 'the_content', $content ); | |
printf( '<div class="blog-intro-content">%s</div>', $content ); | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment