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 badges1 Answer
Reset to default 1There are two options:
Easy (or without coding)
In short, make sure the page has a non-empty content.
Set the "Posts page" to none.
Edit the page you wanted to be the posts page and enter any content — even a space (
) would be sufficient. Save the page.
Now set the "Posts page" to the page you've just edited.
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
评论列表(0条)