Undefined function error when creating Custom Meta Box

Try this

add_action( 'add_meta_boxes', 'cd_meta_box_add' );

function cd_meta_box_add()
{
  add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'cd_meta_box_cb', 'post', 'normal', 'high' );
}

function cd_meta_box_cb()  
{  
  echo 'What you put here, show\'s up in the meta box';     
}  

ps: you have some extra problematic lines, at the top of your code, that I removed, namely:

add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'cd_meta_box_cb', 'post', 'normal', 'high' );

Update:

To add the metabox to your custom post type edit page, replace 'post' with 'your-custom-post-type' in this line:

add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'cd_meta_box_cb', 'your-custom-post-type', 'normal', 'high' );

Leave a Comment