- This topic has 29 replies, 8 voices, and was last updated 2 years, 5 months ago by
Ying.
-
AuthorPosts
-
February 17, 2022 at 2:38 pm #2123351
Elvis
Thanks, then it is exactly what I need.
Still, when I click Default, it reverts to original names.here is the snippet, it is an /inc/colors.php included in functions.php cache is cleared.
// Set Default colors function apuri_set_default_colors( $defaults ) { $defaults['global_colors'] = array( array( 'name' => __( 'Primary Dark', 'generatepress' ), 'slug' => 'primary-dark', 'color' => '#222222', ), array( /* translators: Contrast number */ 'name' => sprintf( __( 'Primary Light', 'generatepress' ) ), 'slug' => 'primary-light', 'color' => '#ffffff', ), array( /* translators: Contrast number */ 'name' => sprintf( __( 'Secondary Dark', 'generatepress' ) ), 'slug' => 'secondary-dark', 'color' => '#a6a6a6', ), array( 'name' => __( 'Secondary Light', 'generatepress' ), 'slug' => 'secondary-light', 'color' => '#eeeeee', ), array( 'name' => __( 'Accent', 'generatepress' ), 'slug' => 'accent', 'color' => '#ff5e5e', ), ); return $defaults; } add_filter( 'generate_option_defaults', 'apuri_set_default_colors' );
Thanks
February 18, 2022 at 8:16 pm #2124898Tom
Lead DeveloperLead DeveloperAh, is this when trying to revert the individual options to their defaults?
If so, you need to do this:
add_filter( 'generate_color_option_defaults', function( $defaults ) { $defaults['color_name'] = 'new-default'; $defaults['another_color_name'] = 'another-new-default'; return $defaults; } );
You can find the color names and current defaults here: https://github.com/tomusborne/generatepress/blob/3.1.3/inc/defaults.php#L123-L190
February 19, 2022 at 8:28 am #2125498Elvis
YES, that is it.
I want to set the defaults to my values and names, but not loose any of customizer functionality. 🙂
Thanks so much.February 19, 2022 at 6:22 pm #2125885Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
February 21, 2022 at 9:33 am #2127867Elvis
Hello,
here I come again 🙂It does not work still. This is in my /inc/global_colors.php file required from functions.php My colors are called like I want and they have values I want, but when open, Typography, Body, Text Color, that has been set to my ‘primary-dark’, if I click to the button Default, it reverts to ‘contrast’.
/** * Set new colors, and color names * @link https://generatepress.com/forums/topic/changing-global-colors-programatically/#post-2122087 */ function apuri_set_default_colors( $defaults ) { $defaults['global_colors'] = array( array( 'name' => __( 'Primary Dark', 'apuri' ), 'slug' => 'primary-dark', 'color' => '#222222', ), array( 'name' => sprintf( __( 'Primary Light', 'apuri' ) ), 'slug' => 'primary-light', 'color' => '#ffffff', ), array( 'name' => sprintf( __( 'Secondary Dark', 'apuri' ) ), 'slug' => 'secondary-dark', 'color' => '#a6a6a6', ), array( 'name' => __( 'Secondary Light', 'apuri' ), 'slug' => 'secondary-light', 'color' => '#eeeeee', ), array( 'name' => __( 'Accent', 'apuri' ), 'slug' => 'accent', 'color' => '#ff5e5e', ), ); return $defaults; } add_filter( 'generate_option_defaults', 'apuri_set_default_colors' ); /** * Set new defaults, to use in customizer * @link https://generatepress.com/forums/topic/changing-global-colors-programatically/page/2/#post-2124898 */ function apuri_reset_new_color_defaults_for_customizer( $defaults ) { $defaults['contrast'] = 'primary-dark'; $defaults['base-2'] = 'primary-light'; $defaults['contrast-2'] = 'secondary-dark'; $defaults['base-3'] = 'secondary-light'; $defaults['accent'] = 'accent'; return $defaults; } add_filter( 'generate_color_option_defaults', 'apuri_reset_new_color_defaults_for_customizer');
February 21, 2022 at 6:30 pm #2128336Tom
Lead DeveloperLead DeveloperHi there,
Those aren’t the correct option names.
For example, the option name on the following line is
top_bar_background_color
: https://github.com/tomusborne/generatepress/blob/3.1.3/inc/defaults.php#L123So you would do this:
$defaults['top_bar_background_color'] = 'primary-dark';
Hope this helps!
February 22, 2022 at 3:16 am #2128716Elvis
[edited]
Tom Thanks a lot,
I got it solved!This syntax works.
$defaults['navigation_search_background_color'] = 'var(--primary-light)'; $defaults['navigation_search_text_color'] = 'var(--secondary-dark)'; $defaults['content_background_color'] = 'var(--primary-light)'; $defaults['content_text_color'] = 'var(--primary-dark)';
Woohooo!
February 22, 2022 at 8:06 pm #2129937Tom
Lead DeveloperLead DeveloperGlad you got it sorted 🙂
April 8, 2023 at 6:53 am #2602040Steve
Hi Tom,
Is your code you posted back on the previous page (#2122087) still valid?
I have copied and pasted that into WPCodebox but it doesn’t seem to be having any effect – I’m making the accent black for example just to see if it’s working but there appears to be no change to the global colours in the customiser at all (accent remains blue)
April 8, 2023 at 12:03 pm #2602394Ying
StaffCustomer SupportHi there,
The code is still valid.
It only changes the default color which is #1e73be for Accent, if you’ve already changed the color, then the code would not have any effect.
April 8, 2023 at 12:09 pm #2602401Steve
hmmm strange – I wonder why it isn’t working then?
I had not changed the default accent colour – it is still showing as #1e73be in the customiser.
April 8, 2023 at 12:26 pm #2602413Ying
StaffCustomer SupportIn that case, this code should still work.
I haven’t tried WPCodebox plugin, can you try using Code snippet to add the code?
April 8, 2023 at 12:42 pm #2602429April 9, 2023 at 10:04 am #2603178Steve
I just don’t understand why the generate_option_defaults filter isn’t working.
I have lots of other snippets working in WPCodebox
Also this color settings code which I found elsewhere on the forum works fine – although this permanently sets the colours, not just setting default values:
<?php add_filter( 'option_generate_settings', function( $settings ) { $settings['global_colors'] = [ [ 'name' => __( 'contrast', 'generatepress' ), 'slug' => 'contrast', 'color' => '#8cff44', ], [ 'name' => sprintf( __( 'Contrast %s', 'generatepress' ), '2' ), 'slug' => 'contrast-2', 'color' => '#29cc14', ], [ 'name' => sprintf( __( 'Contrast %s', 'generatepress' ), '3' ), 'slug' => 'contrast-3', 'color' => '#c2cec7', ], [ 'name' => __( 'base', 'generatepress' ), 'slug' => 'base', 'color' => '#f0f0f0', ], [ 'name' => sprintf( __( 'Base %s', 'generatepress' ), '2' ), 'slug' => 'base-2', 'color' => '#f0f7ff', ], [ 'name' => sprintf( __( 'Base %s', 'generatepress' ), '3' ), 'slug' => 'base-3', 'color' => '#ffffff', ], [ 'name' => __( 'accent', 'generatepress' ), 'slug' => 'accent', 'color' => '#f1276a', ], ]; return $settings; } );
April 9, 2023 at 11:04 am #2603240Ying
StaffCustomer SupportI would recommend disabling all your plugins except GP premium and the plugin inserting PHP code to test.
Also, disable all your other custom functions to eliminate conflicts.
If you are using a child theme, switch to the parent theme.
-
AuthorPosts
- You must be logged in to reply to this topic.