• I’m a junior WordPress developer and new to CMB2 metaboxes framework. I’ve however used ACF plugin before to work with custom fields in WordPress. I don’t want to follow this rout anymore as it’s not the best way to go in my opinion. Here’s my problem. I’d like to use CMB2 to create my theme’s options pages and subpages. Problem is that I don’t seem to get it work. The example code provided by the CMB2 wiki does create a Site Options page but then it creates only one central parent place/page to manage everything. I want to able able to create submenu pages in my Theme Options section under which I can logically organize my theme settings/control options. This is what I’m trying so far; In my functions.php file I call another file function-admin.php like this:

    /**
     * Load Admin Pages.
     */
        require get_template_directory() . '/inc/function-admin.php';
    
    which in turn calls two different submenu pages like this:
    
    <?php
    
    /**
    * ADMIN PAGE
    */
    
    //Generate Tactile Theme Admin Page
    function tactile_add_admin_page() {
    	add_menu_page( 'Tactile Theme Options', 'Tactile ', 'manage_options', 'crete_Tactile ', 'tactile _theme_create_page', '', 61 );
    
    	//Generate TactileTheme Admin Subpages
    	add_submenu_page( 'crete_tactile', 'Tactile Theme Options', 'Theme Options', 'manage_options', 'crethande_tactile', 'tactile_theme_create_page' );
    
    	add_submenu_page( 'crethande_tactile', 'Color Central', 'Color Settings', 'manage_options', 'crete_tactile_color ', 'tactile_theme_settings_page' );
    	//Activate Custom Settings
    	add_action( 'admin_menu', 'tactile _custom_settings' );
    
    }
    	//Activate Admin theme options page
    	add_action( 'admin_menu', 'lawyeah_add_admin_page');
    
    function tactile _theme_create_page() {
    	//generate general settings page
    	require_once( get_template_directory().'/inc/templates/General_settings.php' );
    }
    function tactile_css_options() {
    	//Example Function
    }
    function tactile_sitewide_color () {
    	//Example Function
    }
    function tactile_theme_settings_page() {
    	//generate submenu pages
    	require_once( get_template_directory().'/inc/templates/tactile-admin.php' );
    }

    The problems is how do I get CMB2 metaboxes and custom fields to show on anyone of these created subpages so that I have the liberty and ability to create the custom fields and metaboxes I want just on the subpages I want them to appear on? I’ve so far tried requiring the CMB2 sample code from the submenu pages as a test but to no avail. I’ve tried to edit the CMB2 example-functions.php so as to prevent it from only showing on normal website pages still to no avail. I’ve also tried changing the location of the CMB2 installation folder to where the function-admin.php is but still to no avail. The Admin parent page and submenu pages show up in the Dashboard but they are blank. The html code I write in them shows up but not the a single CMB2 metabox or field. Someone please help me find a way around this cause I feel terribly defeated on how to go about it using CMB2.

  • The topic ‘How to display custom metaboxes on Admin submenu page with CMB2 framework’ is closed to new replies.