Last active
December 8, 2018 12:52
-
-
Save cameronjonesweb/db0a3e4f6765d75df2d5653bb29f09ef to your computer and use it in GitHub Desktop.
Add back the WYSIWYG content editor to the WordPress blog page and display the content on the front end
This file contains 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 | |
/** | |
* Add the WYSIWYG editor back to the blog page | |
* | |
* @param WP_Post $post The post object | |
*/ | |
function cameronjonesweb_fix_no_editor_on_blog_page( $post ) { | |
if( $post->ID === get_option( 'page_for_posts' ) ) { | |
add_post_type_support( 'page', 'editor' ); | |
} | |
} | |
add_action( 'edit_form_after_title', 'cameronjonesweb_fix_no_editor_on_blog_page' ); | |
/** | |
* Display the blog page content before the posts listings | |
*/ | |
function cameronjonesweb_blog_page_content() { | |
if ( is_home() ) { | |
$content = apply_filters( 'the_content', get_post_field( 'post_content', get_option( 'page_for_posts' ) ) ); | |
echo wp_kses_post( $content ); | |
} | |
} | |
add_action( 'loop_start', 'cameronjonesweb_blog_page_content' ); |
This file contains 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 | |
/** | |
* Allow the blog page to be edited using the Gutenberg plugin on WordPress 4.9.8 | |
* | |
* @param bool $can_edit Whether the post can be edited or not. | |
* @param WP_Post $post The post object | |
* @return bool | |
*/ | |
function cameronjonesweb_fix_no_gutenberg_on_blog_page( $can_edit, $post ) { | |
if( $post->ID === intval( get_option( 'page_for_posts' ) ) ) { | |
$can_edit = true; | |
} | |
return $can_edit; | |
} | |
add_filter( 'gutenberg_can_edit_post', 'cameronjonesweb_fix_no_gutenberg_on_blog_page' ); | |
add_filter( 'use_block_editor_for_post', 'cameronjonesweb_fix_no_gutenberg_on_blog_page' ); |
This file contains 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 | |
/** | |
* Display the blog page content before the posts listings only on the first page | |
*/ | |
function cameronjonesweb_blog_page_content() { | |
if ( is_home() && ! is_paged() ) { | |
$content = apply_filters( 'the_content', get_post_field( 'post_content', get_option( 'page_for_posts' ) ) ); | |
echo wp_kses_post( $content ); | |
} | |
} | |
add_action( 'loop_start', 'cameronjonesweb_blog_page_content' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment