MainDashboardButton 是一个 SlotFill,用于替换文章编辑器中的默认主仪表板按钮,在 WordPress 6.2 及更高版本中,站点编辑器不再支持此功能。它主要用于在全屏编辑模式下返回 wp-admin 仪表板。
import { registerPlugin } from '@wordpress/plugins';
import { __experimentalMainDashboardButton as MainDashboardButton } from '@wordpress/edit-post';
import { close } from '@wordpress/icons';
const MainDashboardButtonTest = () => (
<MainDashboardButton>
<FullscreenModeClose icon={ close } />
</MainDashboardButton>
);
registerPlugin( 'main-dashboard-button-test', {
render: MainDashboardButtonTest,
} );import { registerPlugin } from '@wordpress/plugins';
import {
__experimentalFullscreenModeClose as FullscreenModeClose,
__experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/edit-post';
import { external } from '@wordpress/icons';
const MainDashboardButtonIconTest = () => (
<MainDashboardButton>
<FullscreenModeClose icon={ external } href="https://wordpress.org" />
</MainDashboardButton>
);
registerPlugin( 'main-dashboard-button-icon-test', {
render: MainDashboardButtonIconTest,
} );MainDashboardButton 是实验性功能,可能在未来版本中修改或移除,建议在开发中谨慎使用并关注更新。
This slot allows replacing the default main dashboard button in the post editor. It is no longer available in the site editor as of WordPress 6.2.
It’s used for returning back to main wp-admin dashboard when editor is in fullscreen mode.
This will replace the W icon button in the header with a close icon.
import { registerPlugin } from '@wordpress/plugins';
import { __experimentalMainDashboardButton as MainDashboardButton } from '@wordpress/edit-post';
import { close } from '@wordpress/icons';
const MainDashboardButtonTest = () => (
<MainDashboardButton>
<FullscreenModeClose icon={ close } />
</MainDashboardButton>
);
registerPlugin( 'main-dashboard-button-test', {
render: MainDashboardButtonTest,
} );

This example will change the icon in the header to indicate an external link that will take the user to https://wordpress.org when clicked.
import { registerPlugin } from '@wordpress/plugins';
import {
__experimentalFullscreenModeClose as FullscreenModeClose,
__experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/edit-post';
import { external } from '@wordpress/icons';
const MainDashboardButtonIconTest = () => (
<MainDashboardButton>
<FullscreenModeClose icon={ external } href="https://wordpress.org" />
</MainDashboardButton>
);
registerPlugin( 'main-dashboard-button-icon-test', {
render: MainDashboardButtonIconTest,
} );
