0

I am trying to create a meta box as a plugin in my WordPress test website.

I am using an installed custom theme from a tutorial I am following from Udemy called, 'WordPress E-Commerce Development w/ WooCommerce & Storefront'. I have copied the parent theme and have created the child theme as per the tutorial directions.

Instead of implementing the 'Advanced Custom Fields' plugin as directed in the tutorial, I decided to go and create my own custom plugin for creating a meta box.

I have a added a folder(simple-homepage-field) in the wp-content/plugins, and the plugin file as simple-homepage-fields.php

I have activated the plugin and have this code:

function add_homepage_meta_box() { add_meta_box( 'homepage_meta_box', // $id 'Banner Fields', // $title 'homepage_meta_box_display', // $callback 'page', // $screen 'normal', // $context 'high' // $priority ); } add_action('add_meta_boxes', 'add_homepage_meta_box'); 

I was hoping this would work, but it has thrown this error and I dont know why or how to fix it:

enter image description here

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'homepage_meta_box_display' not found or invalid function name in C:\wamp64\www\carolinaspa\wp-admin\includes\template.php on line 1343

Why would this interfere/clash with this function??

Any help will be appreciated. Thanks

    1 Answer 1

    2

    Because the third parameter/argument in the add_meta_box function expects a callback function name, which in your case as you have supplied is homepage_meta_box_display. However you still haven't defined that function yet.

    The callback function is basically used to output the meta box content, anything that you would like to show up in the metabox you are creating. So you should supposedly be defining the function in a manner shown below:

    function homepage_meta_box_display( $post, $metabox ) { echo 'Whatever goes here shows up in the metabox'; } 

    You can change it to whatever you want the metabox to display. Additional reference: https://developer.wordpress.org/reference/functions/add_meta_box/. And there is an example on that page too: https://developer.wordpress.org/reference/functions/add_meta_box/#div-comment-342.

    1
    • Ahh, shit! I did not know that. I have been following additional online tutorials on how to create the custom meta box and a lot of them had nothing between the parentheses, so that is probably why. wow, I don't know PHP at all. Thank you for your help, much appreciated!
      – Krys
      CommentedJan 27, 2020 at 12:41

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.