Archived topic
Set default stying for the off canvas panel programatically
9 replies · Started by David on April 3, 2023
Hi, I'd like to set some defaults in functions.php for styling of the off canvas panel. Could you please help with a filter for this? Thanks! David
Hi David,
Try adding these snippets:
add_filter( 'generate_color_option_defaults', 'new_generate_menu_plus_color_defaults' );
function new_generate_menu_plus_color_defaults( $defaults ) {
$defaults['slideout_background_color'] = '';
$defaults['slideout_text_color'] = '';
$defaults['slideout_background_hover_color'] = '';
$defaults['slideout_text_hover_color'] = '';
$defaults['slideout_background_current_color'] = '';
$defaults['slideout_text_current_color'] = '';
$defaults['slideout_submenu_background_color'] = '';
$defaults['slideout_submenu_text_color'] = '';
$defaults['slideout_submenu_background_hover_color'] = '';
$defaults['slideout_submenu_text_hover_color'] = '';
$defaults['slideout_submenu_background_current_color'] = '';
$defaults['slideout_submenu_text_current_color'] = '';
return $defaults;
}
add_filter( 'generate_font_option_defaults', 'new_generate_menu_plus_typography_defaults' );
function new_generate_menu_plus_typography_defaults( $defaults ) {
$defaults['slideout_font_weight'] = 'normal';
$defaults['slideout_font_transform'] = 'none';
$defaults['slideout_font_size'] = '';
$defaults['slideout_mobile_font_size'] = '';
return $defaults;
}
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Great, thank you Fernando. On the same note, can font-weight also be set this way for the normal primary navigation? Thanks! David
You can add one line of 'navigation_font_weight' to Fernando's code, here's the updated version:
function new_generate_menu_plus_typography_defaults( $defaults ) {
$defaults['slideout_font_weight'] = 'normal';
$defaults['slideout_font_transform'] = 'none';
$defaults['slideout_font_size'] = '';
$defaults['slideout_mobile_font_size'] = '';
$defaults['navigation_font_weight'] => 'normal',
return $defaults;
}
Hi Fernando / Ying, I can;t seem to get any filter to work on 'generate_font_option_defaults' which is strange. My full function is:
add_filter( 'generate_font_option_defaults', 'ffdv_ext_font_defaults' );
function ffdv_ext_font_defaults( $ext_font_defaults ) {
$ext_font_defaults['slideout_font_size'] = '20';
$ext_font_defaults['slideout_mobile_font_size'] = '17';
$ext_font_defaults['slideout_font_weight'] = '600';
$ext_font_defaults['slideout_font_transform'] = '';
return $ext_font_defaults;
}
Hi David,
Can you make sure that there are no syntax errors or slanted quotation marks?
Hi Fernando,
The syntax is all good, still no luck with this.
Thanks!
Hi there,
the generate_font_option_defaults is for the old Typography system. Where a default option existed for every typography setting.
This don't work with the new dynamic typography system as there are no defaults. Typography rules only exist if you create them.
If you want to set typography in a child theme then add them to yours styles.css.
Thanks as always David...
You're welcome