I'm doing some custom coding and creating a new page template to use for a new page within Wordpress. I'm trying to add a meta box to the page to be displayed as output to the user. I tried to do the following in my page template:

add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' );

When I go to the URL to display the new page I created I get the following error message: Fatal error: Call to undefined function get_current_screen() in D:\My Documents\xampp_new\xampp\htdocs\bmt\wp-admin\includes\template.php on line 921

How can I add meta boxes to be displayed to an end user?

  • I want to say that Metaboxes were designed for admin-panel / backend use only but maybe somebody here has a solution for you.
    – Howdy_McGee
    Jan 13 '15 at 19:41
  • @Howdy_McGee No, you're right, meta boxes were designed for the admin area of the site. You'd display the post meta info that you save using a meta box, on the front end.
    – darrinb
    Jan 13 '15 at 22:07

By default WordPress doesn't load admin classes/function definitions in the front end of the site. You need to explicitly require the files.

As far as I remember requiring wp-admin/includes/admin.php would get you most of typical stuff.

  • I got rid of the original error by including this file. I did however get another one. I'm still using this code: add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' ); The error message I'm getting now is: Warning: array_keys() expects parameter 1 to be array, null given in D:\My Documents\xampp_new\xampp\htdocs\bmt\wp-admin\includes\plugin.php on line 1676 Warning: Invalid argument supplied for foreach() in D:\My Documents\xampp_new\xampp\htdocs\bmt\wp-admin\includes\plugin.php on line 1676 Jan 14 '15 at 15:37
  • Actually only including that file on my page creates that warning. Jan 14 '15 at 15:44
  • It's hard to tell because there is no loop at that line in current WP version (4.1).
    – Rarst
    Jan 14 '15 at 15:50
  • Ok, I guess I'll just have to code this portion by myself. Thanks. Jan 14 '15 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.