Meta Boxes: Editing Post and Page Options

In this tutorial, I’ll provide some examples in editing the meta boxes that come packaged with your theme.

In the last tutorial, we created a custom meta box from scratch using the framework’s Theme_Blvd_Meta_Box() class. In the framework, we use this same class to build out your theme’s packaged meta boxes. And in order to make this all extendable from your child theme or plugin, we pass all this data as filterable arrays.

To get the best understanding of this, I suggest having a look at the following file of your theme.

/framework/admin/meta/meta.php

For every meta box created, there is a corresponding function of filterable arguments passed to it. You can use these filters to edit the attributes of the meta box, edit options, add options, remove options, etc.

For any meta box you want to edit, you can find all the data in this meta.php file. So, if you’re wanting an exact filter name or an exact piece of data to edit for a meta box, you’ll find it there, for reference.

Examples

Display Post Options When Editing Custom Post Types

/**
 * Display "Post Options" meta box when
 * editing custom post types, foo and bar.
 */
function my_post_meta( $setup ) {
 
    $setup['config']['page'][] = 'foo';
    $setup['config']['page'][] = 'bar';
     
    return $setup;
}
add_filter('themeblvd_post_meta', 'my_post_meta');

Change the Meta Box Titles

/**
 * Change the title of the "Post Options" 
 * meta box to "Theme Blvd Options"
 */
function my_post_meta( $setup ) {
 
    $setup['config']['title'] = 'Theme Blvd Options';
     
    return $setup;
}
add_filter('themeblvd_post_meta', 'my_post_meta');
/**
 * Change the title of the "Page Options" 
 * meta box to "Theme Blvd Options"
 */
function my_page_meta( $setup ) {
 
    $setup['config']['title'] = 'Theme Blvd Options';
     
    return $setup;
}
add_filter('themeblvd_page_meta', 'my_page_meta');

Add an Option

/**
 * Add a text input option to the 
 * "Post Options" meta box.
 */
function my_post_meta( $setup ) {
 
    $setup['options'][] = array(
        'name'      => 'My Option',
        'desc'      => 'This is the description for the option.',
        'id'        => '_my_option',
        'std'       => 'default value for option',
        'type'      => 'text'
    );
     
    return $setup;
}
add_filter('themeblvd_post_meta', 'my_post_meta');
/**
 * Add a text input option to the 
 * "Page Options" meta box.
 */
function my_page_meta( $setup ) {
 
    $setup['options'][] = array(
        'name'      => 'My Option',
        'desc'      => 'This is the description for the option.',
        'id'        => '_my_option',
        'std'       => 'default value for option',
        'type'      => 'text'
    );
     
    return $setup;
}
add_filter('themeblvd_page_meta', 'my_page_meta');
Note: For more on formatting options, see this tutorial.

Remove an Option

/**
 * Remove Sidebar Layout option from 
 * "Post Options" meta box.
 */
function my_post_meta( $setup ) {

    unset( $setup['options']['tb_sidebar_layout'] );
     
    return $setup;
}
add_filter('themeblvd_post_meta', 'my_post_meta');
/**
 * Remove Breadcrumbs option from 
 * "Page Options" meta box.
 */
function my_page_meta( $setup ) {
 
    unset( $setup['options']['tb_breadcrumbs'] );
     
    return $setup;
}
add_filter('themeblvd_page_meta', 'my_page_meta');

Edit a Default Value for an Option

/**
 * Change default value of the Featured 
 * Image Link option in "Post Options" 
 * meta box.
 */
function my_post_meta( $setup ) {

    $setup['options']['tb_thumb_link']['std'] = 'post';
     
    return $setup;
}
add_filter('themeblvd_post_meta', 'my_post_meta');
/**
 * Change default value of the Featured 
 * Image Link option in "Page Options" 
 * meta box.
 */
function my_page_meta( $setup ) {
 
    $setup['options']['tb_thumb_link']['std'] = 'post';
     
    return $setup;
}
add_filter('themeblvd_page_meta', 'my_page_meta');

Remove Post and Page Options, All Together

/**
 * Remove "Post Options" and "Page Options"
 * meta boxes, all together.
 */
function my_global_config($config) {
    $config['meta']['post_options'] = false;
    $config['meta']['page_options'] = false;
    return $config;
}
add_filter('themeblvd_global_config', 'my_global_config');