8

In WordPress 4.2 it included a nice feature which labeled what page was the Front-Page and which page was the Blog ( Latest Posts ). Unfortunately, it also removes the default editor on the page assigned to show the latest posts and instead shows this message:

You are currently editing the page that shows your latest posts.

I want to assign content to the blog page to show above my latests posts via:

get_post_field( 'post_content', get_option( 'page_for_posts' ) );

How can I re-add the default WP Editor to the Blog Page in the administration panel without adding a separate metabox?

1
  • I had the same problem with wordpress 5. Editor was missing from the Blog page. I just trashed the default blog page created by wordpress and restored it from the trash. Now the restored blog page is having the default editor.
    – Rinto Vr
    Mar 22, 2019 at 9:16

2 Answers 2

16

In WordPress 4.2 the editor was removed on whichever page was assigned to show Latest Posts for whatever reason. The following function below ( original solution found here by crgeary ) will re-add the editor and remove the notification:

You are currently editing the page that shows your latest posts.

Here's some information on the hooks used:


if( ! function_exists( 'fix_no_editor_on_posts_page' ) ) {

    /**
     * Add the wp-editor back into WordPress after it was removed in 4.2.2.
     *
     * @param Object $post
     * @return void
     */
    function fix_no_editor_on_posts_page( $post ) {
        if( isset( $post ) && $post->ID != get_option('page_for_posts') ) {
            return;
        }

        remove_action( 'edit_form_after_title', '_wp_posts_page_notice' );
        add_post_type_support( 'page', 'editor' );
    }
    add_action( 'edit_form_after_title', 'fix_no_editor_on_posts_page', 0 );
 }

Edit for WordPress 4.9

As of WordPress 4.9.6 this fails to re-instate the editor. It looks as though the action edit_form_after_title isn't called soon enough. This modification, called on the earliest non-deprecated hook following the editor's removal in edit-form-advanced.php, seems to work OK.

Apart from the change of hook, there's a change to the number of parameters too.

if( ! function_exists( 'fix_no_editor_on_posts_page' ) ) {

    function fix_no_editor_on_posts_page( $post_type, $post ) {
        if( isset( $post ) && $post->ID != get_option('page_for_posts') ) {
            return;
        }

        remove_action( 'edit_form_after_title', '_wp_posts_page_notice' );
        add_post_type_support( 'page', 'editor' );
    }

    add_action( 'add_meta_boxes', 'fix_no_editor_on_posts_page', 0, 2 );

 }
2
  • As of WordPress 4.9 this still removes the notice but doesn't re-instate the editor. Jul 4, 2018 at 16:59
  • 1
    Added an edit explaining what seems to have changed between WP4.2 and WP4.9. Hope that's the way to do things - didn't seem I should add a new answer. Jul 4, 2018 at 17:27
9

It's been a while, but I came across this topic while looking for a way to enable gutenberg editor on the Blog Page. Didn't find any clue in google, so I dived into wordpress code and found the solution. Here is the code:

add_filter( 'replace_editor', 'enable_gutenberg_editor_for_blog_page', 10, 2 );
/**
 * Simulate non-empty content to enable Gutenberg editor
 *
 * @param bool    $replace Whether to replace the editor.
 * @param WP_Post $post    Post object.
 * @return bool
 */
function enable_gutenberg_editor_for_blog_page( $replace, $post ) {

    if ( ! $replace && absint( get_option( 'page_for_posts' ) ) === $post->ID && empty( $post->post_content ) ) {
        // This comment will be removed by Gutenberg since it won't parse into block.
        $post->post_content = '<!--non-empty-content-->';
    }

    return $replace;

}

I used 'replace_editor' filter just because it is the last filter/action used before the check if Gutenberg should load. This could be any earlier filter or action with current post object available.

WordPress checks for two things: if the current post ID is the same as page_for_posts option and if the content is empty, so in this filter we just add some fake content which will be removed by Gutenberg since it is random HTML comment.

Hope someone will find it useful :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.