Reset a metabox color picker to “none” instead of #191919 in functions.php
-
My theme has a really annoying color pre setting (a colour picker) that I want to change without making changes to the parent theme.
My question is if the below is possible to change within the functions.php ?Set a metabox colurpicker to “none”
'default' => ''
instad of'default' => '#191919'
The original code is in a file in parent theme called metaboxes.php and looks like this:
$cmb_title->add_field( array( 'name' => __( 'Title Text Color', 'wassap' ), 'id' => $prefix . 'color', 'type' => 'colorpicker', 'default' => '#191919' ) );
And again – what I want to do is to set the default to
'default' => ''
with the help of funcions.php if that is possible!Thank you
-
Hi johan,
I need to check function of this code and also need to be check which action or filter it is used.
So, please provide me those details so I can help to resolve your issue.
It can definitely be done but you’ll need to tell me the metabox ID. Find the part where you see
$cmb_title = new_cmb2_box(
… and let me know what the'id'
property is for the box. I’ll also need to know what the$prefix
value is (look for the place where you see$prefix = 'SOMEVALUE_';
).Hello and thanks for your replies!
@jtsternberg
I guess you mean this part?Prefix:
$prefix = '_weston_header_';
Is this the ID you mean:
$cmb_title = new_cmb2_box( array( 'id' => $prefix . 'options', 'title' => __( 'Title Area Options', 'weston' ), 'object_types' => array( 'page', 'project', 'post', 'product'), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true ) );
That should do it as long as the prefixes match. So this should do it:
function yourprefix_update_header_color_field_default() { $cmb = cmb2_get_metabox( '_weston_header_options' ); if ( $cmb ) { $cmb->update_field_property( '_weston_header_color', 'default', '' ); } } add_action( 'cmb2_init_before_hookup', 'yourprefix_update_header_color_field_default' );
@jtsternberg I tried to copy this to the child theme funcions.php but when creating a new page it sill picks #191919 as default I’m afraid….
Don’t know if you need this but this is the whole part reguarding the Header Options and Title Options…
//Header Options add_action( 'cmb2_init', 'weston_register_header_metabox' ); function weston_register_header_metabox() { $prefix = '_weston_header_'; $cmb_header = new_cmb2_box( array( 'id' => $prefix . 'options', 'title' => __( 'Header Options', 'weston' ), 'object_types' => array( 'project','page','post', 'product' ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true ) ); $cmb_header->add_field( array( 'name' => __( 'Hide Header', 'weston' ), 'desc' => __( 'Choose to hide or show the header on this page.', 'weston' ), 'id' => $prefix . 'hide', 'type' => 'select', 'options' => array( 'no' => __( 'No', 'weston' ), 'yes' => __( 'Yes', 'weston' ) ), ) ); $cmb_header->add_field( array( 'name' => __( 'Transparent Background', 'weston' ), 'desc' => __( 'Make the site header background transparent on this page.', 'weston' ), 'id' => $prefix . 'transparent_bg', 'type' => 'select', 'options' => array( 'no' => __( 'No', 'weston' ), 'yes' => __( 'Yes', 'weston' ) ), ) ); $cmb_header->add_field( array( 'name' => __( 'Color Scheme', 'weston' ), 'desc' => __( 'Make the contents of the header light or dark for this page. Only applies if Transparent Background is enabled.', 'weston' ), 'id' => $prefix . 'color_scheme', 'type' => 'select', 'options' => array( 'dark' => __( 'Dark', 'weston' ), 'light' => __( 'Light', 'weston' ) ), ) ); $cmb_header->add_field( array( 'name' => __( 'Menu Color', 'weston' ), 'id' => $prefix . 'menu_color', 'type' => 'colorpicker', 'default' => '' ) ); $cmb_header->add_field( array( 'name' => __( 'Menu Color Hover', 'weston' ), 'id' => $prefix . 'menu_hover_color', 'type' => 'colorpicker', 'default' => '' ) ); $cmb_header->add_field( array( 'name' => __( 'Main Menu', 'weston' ), 'desc' => __( 'Select a different main menu to show on this page.', 'weston' ), 'id' => $prefix . 'menu_main', 'type' => 'select', 'options' => customMenus(), ) ); $cmb_header->add_field( array( 'name' => __( 'Mobile Menu', 'weston' ), 'desc' => __( 'Select a different mobile menu to show on this page.', 'weston' ), 'id' => $prefix . 'menu_mobile', 'type' => 'select', 'options' => customMenus(), ) ); $cmb_header->add_field( array( 'name' => __( 'Left Menu (Split Header)', 'weston' ), 'desc' => __( 'Select a different left menu to show on this page. For use with Split Header layout.', 'weston' ), 'id' => $prefix . 'menu_left', 'type' => 'select', 'options' => customMenus(), ) ); } //Title Options add_action( 'cmb2_init', 'weston_register_title_metabox' ); function weston_register_title_metabox() { $prefix = '_weston_title_'; $cmb_title = new_cmb2_box( array( 'id' => $prefix . 'options', 'title' => __( 'Title Area Options', 'weston' ), 'object_types' => array( 'page', 'project', 'post', 'product'), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true ) ); $cmb_title->add_field( array( 'name' => __( 'Show Title Area', 'weston' ), 'desc' => __( 'Hide or show the page title area.', 'weston' ), 'id' => $prefix . 'show', 'type' => 'select', 'show_option_none' => false, 'options' => array( 'yes' => __( 'Yes', 'weston' ), 'no' => __( 'No', 'weston' ), ), ) ); $cmb_title->add_field( array( 'name' => __( 'Subtitle Text', 'weston' ), 'desc' => __( 'This text will be displayed below the title on pages and projects.', 'weston' ), 'id' => $prefix . 'subtitle', 'type' => 'text' ) ); $cmb_title->add_field( array( 'name' => __( 'Hide Text', 'weston' ), 'id' => $prefix . 'hide_text', 'type' => 'select', 'options' => array( 'no' => __( 'No', 'weston' ), 'yes' => __( 'Yes', 'weston' ), ), ) ); $cmb_title->add_field( array( 'name' => __( 'Title Image', 'weston' ), 'desc' => __( 'This image will appear above the title text.', 'weston' ), 'id' => $prefix . 'img', 'type' => 'file', ) ); $cmb_title->add_field( array( 'name' => __( 'Title Alignment', 'weston' ), 'id' => $prefix . 'alignment', 'type' => 'select', 'options' => array( '' => __( 'Default', 'weston' ), 'center' => __( 'Center', 'weston' ), 'left' => __( 'Left', 'weston' ), 'right' => __( 'Right', 'weston' ) ), ) ); $cmb_title->add_field( array( 'name' => __( 'Title Area Height', 'weston' ), 'desc' => __( 'Set the height of the title area in pixels. (ex. 400)', 'weston' ), 'id' => $prefix . 'area_height', 'type' => 'text_small' ) ); $cmb_title->add_field( array( 'name' => __( 'Title Background Image', 'weston' ), 'desc' => __( 'Upload an image or enter a URL.', 'weston' ), 'id' => $prefix . 'bg_img', 'type' => 'file', ) ); $cmb_title->add_field( array( 'name' => __( 'Enable Background Parallax', 'weston' ), 'id' => $prefix . 'parallax', 'type' => 'select', 'options' => array( 'no' => __( 'No', 'weston' ), 'yes' => __( 'Yes', 'weston' ), ), ) ); $cmb_title->add_field( array( 'name' => __( 'Title Text Color', 'weston' ), 'id' => $prefix . 'color', 'type' => 'colorpicker', 'default' => '#FFFFFF' ) ); }
- This reply was modified 7 years ago by Johan.
@jtsternberg
got it! I gave you the wring prefix I think. Just changed it to the_weston_title_
instead and now its working!function no_default_color() { $cmb = cmb2_get_metabox( '_weston_title_options' ); if ( $cmb ) { $cmb->update_field_property( '_weston_title_color', 'default', '' ); } } add_action( 'cmb2_init_before_hookup', 'no_default_color' );
Hello,
you just copy and paste this function in your child theme and make changes as you need. that’s work awesome!!
function weston_register_title_metabox() { $prefix = '_weston_title_'; $cmb_title = new_cmb2_box( array( 'id' => $prefix . 'options', 'title' => __( 'Title Area Options', 'weston' ), 'object_types' => array( 'page', 'project', 'post', 'product'), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true ) ); $cmb_title->add_field( array( 'name' => __( 'Show Title Area', 'weston' ), 'desc' => __( 'Hide or show the page title area.', 'weston' ), 'id' => $prefix . 'show', 'type' => 'select', 'show_option_none' => false, 'options' => array( 'yes' => __( 'Yes', 'weston' ), 'no' => __( 'No', 'weston' ), ), ) ); $cmb_title->add_field( array( 'name' => __( 'Subtitle Text', 'weston' ), 'desc' => __( 'This text will be displayed below the title on pages and projects.', 'weston' ), 'id' => $prefix . 'subtitle', 'type' => 'text' ) ); $cmb_title->add_field( array( 'name' => __( 'Hide Text', 'weston' ), 'id' => $prefix . 'hide_text', 'type' => 'select', 'options' => array( 'no' => __( 'No', 'weston' ), 'yes' => __( 'Yes', 'weston' ), ), ) ); $cmb_title->add_field( array( 'name' => __( 'Title Image', 'weston' ), 'desc' => __( 'This image will appear above the title text.', 'weston' ), 'id' => $prefix . 'img', 'type' => 'file', ) ); $cmb_title->add_field( array( 'name' => __( 'Title Alignment', 'weston' ), 'id' => $prefix . 'alignment', 'type' => 'select', 'options' => array( '' => __( 'Default', 'weston' ), 'center' => __( 'Center', 'weston' ), 'left' => __( 'Left', 'weston' ), 'right' => __( 'Right', 'weston' ) ), ) ); $cmb_title->add_field( array( 'name' => __( 'Title Area Height', 'weston' ), 'desc' => __( 'Set the height of the title area in pixels. (ex. 400)', 'weston' ), 'id' => $prefix . 'area_height', 'type' => 'text_small' ) ); $cmb_title->add_field( array( 'name' => __( 'Title Background Image', 'weston' ), 'desc' => __( 'Upload an image or enter a URL.', 'weston' ), 'id' => $prefix . 'bg_img', 'type' => 'file', ) ); $cmb_title->add_field( array( 'name' => __( 'Enable Background Parallax', 'weston' ), 'id' => $prefix . 'parallax', 'type' => 'select', 'options' => array( 'no' => __( 'No', 'weston' ), 'yes' => __( 'Yes', 'weston' ), ), ) ); $cmb_title->add_field( array( 'name' => __( 'Title Text Color', 'weston' ), 'id' => $prefix . 'color', 'type' => 'colorpicker', 'default' => '' ) ); }
- The topic ‘Reset a metabox color picker to “none” instead of #191919 in functions.php’ is closed to new replies.