how do i make theme options page with this plugin
-
I want make theme option page using CMB2 plugin please help me …….
-
Try out the code in the snippet file here https://github.com/WebDevStudios/CMB2-Snippet-Library/tree/master/options-and-settings-pages
dear sir, i already visited above link but don’t find any solutions.
Please make simple format.
thanks in advance.
Out of curiosity, did you try loading the sample code and seeing what resulted? From what I can tell, all you need to do is download the PHP file as is, drop it into your themes folder, and then include() the file and it’ll create the settings page for you. After that, you’d just need to customize the metaboxes from the add_options_page_metabox() method in the class.
Not sure how much OOP experience you have, if any, though.
Hey @MichaelBeckwith I’ve dropped in that code into my custom metaboxes file and the “Site Options” tab appears in the WP admin. However the options page is blank so it looks like displaying the 2 demo fields does not work out of the box.
Have you seen this happen? Maybe I’m making a mistake, its a big PHP class so that’s def possible. Any help would be appreciated.
Not sure, and haven’t heard of any issues like that, that I can recall. Are you literally just putting one of the files from that snippet library into your theme/plugin and then loading the file? No modifications to it?
Yessir, I’ve been using CMB2 properly for all my metaboxes. Its been amazing. However I’ve added the class to the bottom of my metabox file.
It created the Site Options tab. But the options page itself has only a title.
But I cannot replicate the issue on a fresh WP install. The Site Options page renders 2 metaboxes as expected on a fresh install. Do you have any ideas how to troubleshoot CMB2 that I may have overlooked?
I have shut off all plugins and removed a lot of code try to find some culprit but no luck.
anything showing up for php errors and WP_DEBUG set to true?
@benracicot I believe you use old version of cmb2. Just update your cmb2 and try again. I think it will be work.
@nkhan007 try reading the code and understanding before you make such claims. The plugin author offer already too much support for free to also do your job.
To be fair, we probably have had updates in the past 3 months that may fix issues with the thread. Always good to stay on top of updates.
The Options Page class works well. I’ve been using it for while already.
Ended up in here today because I was trying to find a way to add tabs.
Mixed a similar implementation (that had tabs) from the CMB1 days with the example and is working nicely.
I just had respond because I can not stand that solve my problem for me attitude. Even more when it is directed to a OpenSource project.
The Options Page class works well. I’ve been using it for while already.
Ended up in here today because I was trying to find a way to add tabs.
Mixed a similar implementation (that had tabs) from the CMB1 days with the example and is working nicely.
I just had respond because I can not stand that solve my problem for me attitude. Even more when it is directed to a OpenSource project.
it is what it is.
Ohh all are conversation but not a proper solution can you guide me how to access theme option on admin panel provide me proper guide line i am stuck on that part thank you.
here is code of example-fucntions.php
Just example me how to access admin panel that code Or page Or section
`add_action( ‘cmb2_admin_init’, ‘yourprefix_register_theme_options_metabox’ );
/**
* Hook in and register a metabox to handle a theme options page
*/
function yourprefix_register_theme_options_metabox() {// Start with an underscore to hide fields from custom fields list
$option_key = ‘_yourprefix_theme_options’;/**
* Metabox for an options page. Will not be added automatically, but needs to be called with
* thecmb2_metabox_form
helper function. See wiki for more info.
*/
$cmb_options = new_cmb2_box( array(
‘id’ => $option_key . ‘page’,
‘title’ => __( ‘Theme Options Metabox’, ‘cmb2’ ),
‘hookup’ => false, // Do not need the normal user/post hookup
‘show_on’ => array(
// These are important, don’t remove
‘key’ => ‘options-page’,
‘value’ => array( $option_key )
),
) );/**
* Options fields ids only need
* to be unique within this option group.
* Prefix is not needed.
*/
$cmb_options->add_field( array(
‘name’ => __( ‘Site Background Color’, ‘cmb2’ ),
‘desc’ => __( ‘field description (optional)’, ‘cmb2’ ),
‘id’ => ‘bg_color’,
‘type’ => ‘colorpicker’,
‘default’ => ‘#ffffff’,
) );}
https://github.com/WebDevStudios/CMB2/wiki/Using-CMB-to-create-an-Admin-Theme-Options-Page
Should be able to fetch them with something like the following:
$field_value = myprefix_get_option( 'field_id' );
With the field Id being the ‘id’ field you provide for each $cmb_options->add_field();
Note you’ll want to make sure to have the following available:
but feel free to rename if you need to.
- The topic ‘how do i make theme options page with this plugin’ is closed to new replies.