admin管理员组文章数量:1394099
I'm interested in adding a widget area to the top of the Dashboard page at site URL /wp-admin to display some important notes for the editors/developers of the site.
How would I go about this?
I'm interested in adding a widget area to the top of the Dashboard page at site URL /wp-admin to display some important notes for the editors/developers of the site.
How would I go about this?
Share Improve this question asked Mar 18, 2020 at 21:29 Highly IrregularHighly Irregular 2134 silver badges10 bronze badges 2- 1 Create a dashboard widget wpbeginner/wp-themes/… or developer.wordpress/apis/handbook/dashboard-widgets – Mikhail Commented Mar 18, 2020 at 21:31
- @Mikhail To be clear, do the instructions at developer.wordpress/apis/handbook/dashboard-widgets relate to adding a widget area, or just a widget? Thanks – Highly Irregular Commented Mar 18, 2020 at 21:47
1 Answer
Reset to default 0Let's dig into dashboard's internals to see what we can do. https://core.trac.wordpress/browser/tags/5.3/src/wp-admin/_index.php#L129
First it renders welcome_panel via do_action( 'welcome_panel' );
so you can hook to it and output your custom content on top over all other widgets.
You can also remove_action('welcome_panel')
before attaching your own to remove default or other content from being rendered there, and to render only your own one.
And this is essentially answer to your question. -> you create custom function which will echo your html, that you'd like to be displayed together with or instead of welcome_panel and hook it via add_action( 'welcome_panel', 'your_custom_top_widget_renderer' );
Default welcome panel is attached via add_action( 'welcome_panel', 'wp_welcome_panel' );
You can checkout wp_welcome_panel
function which is used to render welcome panel in WP by default here https://core.trac.wordpress/browser/tags/5.3/src/wp-admin/includes/dashboard.php#L1757 To get a css classes\markup and functionality inspiration for your custom welcome panel renderer.
BUT this isn't a placeholder for dashboard widgets, so essentially you can render there whatever you wish, but out of the box features like drag and drop to reorder or place there some other widgets via drag and drop will not work.
And let's speak about Dashboard widgets.
Looking a bit down below https://core.trac.wordpress/browser/tags/5.3/src/wp-admin/_index.php#L148
shows us wp_dashboard()
function call which is used to render dashboard widgets and their placeholders, so all out of the box drag and drop reorder and other functionality of real dashboard widgets works.
https://core.trac.wordpress/browser/tags/5.3/src/wp-admin/includes/dashboard.php#L230
This function renders widgets and 4 placeholders for widgets and they are in 2 columns UI. So without rewriting this function it's not possible to inject some 5th placeholder or something like that.
UPD: I came up with crazy idea but you can give it a try. you can fire <?php do_meta_boxes( $screen->id, 'top_welcome_custom', '' ); ?>
inside your custom welcome_panel
action function and you'll have metaboxes list rendered there as well. This will require to do JS tricks to make them sortable etc. but who said that it would be straight if we do something really custom.
I hope at least from your explanation that you are going just to display some information there. So no real need for metaboxes.
本文标签: How can I add a widget area to the top of the Dashboard
版权声明:本文标题:How can I add a widget area to the top of the Dashboard? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744658836a2618121.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论