Gutenberg / WordPress-默认情况下打开侧边栏

时间:2020-06-03 19:40:08

标签: wordpress-gutenberg

我想默认在WordPress Gutenberg界面中打开侧边栏。

enter image description here

我写了这段代码:

const isSidebarOpened = wp.data.select( 'core/edit-post' ).isEditorSidebarOpened();

    if ( !isSidebarOpened ) {
        wp.data.select( 'core/edit-post' ).openGeneralSidebar();
    }

该条件起作用,但是功能openGeneralSidebar()不会打开侧边栏。我可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方法。

如果某人想做一天,这是为我工作的代码:

const isSidebarOpened = wp.data.select( 'core/edit-post' ).isEditorSidebarOpened();

if ( !isSidebarOpened ) {
   wp.data.dispatch( 'core/edit-post' ).openGeneralSidebar();
}
相关问题