We’ve added that action for sanitizing data using the Genesis no_html filter. So the next thing we’re going to do then is create a metabox.
Create the Function
The hook that we’re adding this function to is the ‘genesis_theme_settings_metaboxes’. Again, that is an add_action and there’s the hook name ‘genesis_theme_settings_metaboxes’ and then the name of our function and then semicolon at the end of that.
What the Action Does
What this action does is it passes the $admin_pagehook into the function. Essentially, this is a very simple wrapper for the WordPress add_meta_box function. The WordPress add_meta_box function takes the$ id of the metabox, the $title of the metabox. It can take a $callback and a $post_type.
The $callback is the name of the function that populates the metabox and the $post_type, this is an admin metabox – that’s the deal, is more of the general metabox.
The $post_type in this case, is actually the URL of the admin page that the metabox is going to be added to. So what Genesis is doing is it is passing that address to us with this little variable.
We are inside of that, just copy add_meta_box. We’re using the add_meta_box function and so the id of our metabox, I’m going to call ‘byob-front-page-options’ and the title of our metabox is going to be ‘Front Page Featured Categories’.
The $callback is the name of the function that essentially is writing the form. Let’s just copy this name and put the name of the function which is what that’s going to do, that creates the form.
Now $post_type in this case, this is where you take your admin_pagehook and put it there. If you look at this guy’s tutorial, he uses this variable, _genesis_theme_settings_pagehook. This is the actual name of the variable that they use in Genesis to do this, however, the name of it doesn’t matter.
Name of the Variable
The name of the variable here, even if it was named “fishsticks”, it’s capturing the value that’s being passed here and the only thing that really matters is that whatever you call this variable here, is also what you use here.
I don’t really like using this kind of a variable because it suggests to you that the name of this variable is significant and it’s actually not significant. It doesn’t matter what that name is so that’s why I used what I thought was a more descriptive name, admin_pagehook.
It’s essentially the admin page URL and a place on the admin page where it’s going to go and then $context has to do with where on the page it shows up.
Now in this case, your choices for $context are ‘normal’, ‘advanced’ or ‘side’ and in this case, we’re just going to say ‘normal’. Actually, I don’t remember what ‘advanced’ does, ‘side’ puts it in the sidebar but this settings page doesn’t have a side so that doesn’t make any sense.
Let’s take a look at what I did in my test. That’s interesting. I think this is probably because it’s an admin metabox and not post metabox so we’re going to go ahead and borrow that since I know it works, that’s $context and $priority.
What’s Happening in the Function
We don’t need any $callback_args so we’re just going to delete that. We’re essentially using the WordPress function add_meta_box. We’ve given it the slug ‘byob-front-page-options’ or the id, that’s its title. This is the name of the function below that. It sets up the form.
This is the URL and location of the admin page where this is going and the only thing you really need to know about that is that this and this need to be the same no matter what you choose to call this.
Then we’re going to put it in the ‘main’ context and we’re going to give it a ‘high’ priority which means this is going to be up towards the top of the metaboxes on that section.