Support » Themes and Templates » add_meta_box undefined WP 3.1.3

  • I just downloaded and installed WP 3.1.3 for a test site.

    When I try add_meta_box(…) from my custom theme’s functions.php, I get the error in my server log that the function is undefined. The codex claims this function has been around since 2.5.

    Do I need to be using this somewhere else? I looked around for examples on usage and they all seem to be used in functions.php.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Dion Hulse


    Lead Developer

    add_meta_box() is, and always has been, only defined in the admin area.

    You can use add_meta_box() in your themes functions.php, you just need to only execute it on admin requests, for example:

    add_action('admin_init', 'mytheme_admin_init');
    function mytheme_admin_init() {

    Aha, great, thanks! That definitely helps. I was confused because I could do things like have actions for custom post types and lots of other things to do with posts, but apparently not create a meta box for a post without it being in admin_init. Inconsistencies ftl.

    Moderator Dion Hulse


    Lead Developer

    When it comes to the themes functions.php, you shouldn’t really be running anything outside of actions. ie. All code should be wrapped in functions hooked to init or later usually (Aside from theme setup stuff, which can be hooked to ‘after_setup_theme’)

    So the only functions you should call in functions.php are add_filter() and add_action()

    Have a look at TwentyTen’s functions.php for an example of this:

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_meta_box undefined WP 3.1.3’ is closed to new replies.