How to enable Block Editor on the Posts page

When setting a page to be the posts page in Reading Settings (), WordPress automatically disables the editor when editin

When setting a page to be the posts page in Reading Settings (), WordPress automatically disables the editor when editing that page.

Is there any way to revert this and still show the block editor?

When setting a page to be the posts page in Reading Settings (https://cl.ly/b73ffa329174), WordPress automatically disables the editor when editing that page.

Is there any way to revert this and still show the block editor?

Share Improve this question asked Jul 29, 2019 at 16:40 Luis MartinsLuis Martins 2351 gold badge2 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

There are two options:

Easy (or without coding)

In short, make sure the page has a non-empty content.

  1. Set the "Posts page" to none.

  2. Edit the page you wanted to be the posts page and enter any content — even a space () would be sufficient. Save the page.

  3. Now set the "Posts page" to the page you've just edited.

  4. Edit that page and you should now see that the editor is enabled.

Why this works, is because the editor is only being disabled if the page content is empty (i.e. 0-length including spaces).

With custom code

One way is using the update_option_{option} hook to set the post content to (a space) if the content is empty:

add_action( 'update_option_page_for_posts', function( $old_value, $new_value ){
    $post = $new_value ? get_post( $new_value ) : null;
    if ( $post && empty( $post->post_content ) ) {
        wp_update_post( [
            'ID'           => $post->ID,
            'post_content' => ' ', // or try using <!-- comment -->
        ] );
    }
}, 10, 2 );

But first, set the "Posts page" to none; save the settings, then set the "Posts page" to the proper page. Because the hook (update_option_{option}) won't be fired if the option value is the same as the old one. (There are other hooks you can use/try, though.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745285153a4620516.html

相关推荐

  • How to enable Block Editor on the Posts page

    When setting a page to be the posts page in Reading Settings (), WordPress automatically disables the editor when editin

    12小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信