Getting List of all registered dashboard Meta Boxes


I am trying to get a list of all registered meta boxes in the wordpress admin, specifically the dashboard meta boxes.

Now this is easily achieved with the global variable $wp_meta_boxes and does exactly what I need but only when on the dashboard page.

If I am on a custom admin page or a setting page for example, I get nothing. I am trying to get a list of dashboard metaboxes and give users the option to put them on a different custom admin page / dashboard.

There are a couple of other similar questions to getting these meta boxes and I am aware of the following code that is been given as an answer, however it has the same problem and it returns an empty array if not on the dashboard page:

function get_meta_boxes( $screen = null, $context = 'advanced' ) {
global $wp_meta_boxes;

if ( empty( $screen ) )
    $screen = get_current_screen();
elseif ( is_string( $screen ) )
    $screen = convert_to_screen( $screen );

$page = $screen->id;

return $wp_meta_boxes[$page][$context];

Anyone have any ideas? Should the $wp_meta_boxes be working and there is something going on with my setup? Or is there another way of doing this?

Any help would be massively appreciated!

, , Mark 2 years 2020-09-01T10:10:23-05:00 0 Answers 51 views 0

Leave an answer