- This topic has 13 replies, 9 voices, and was last updated 1 year, 1 month ago by Greg.
-
AuthorPosts
-
June 10, 2020 at 8:57 am #1322367Jaime Martinez
Hi there,
In this case I’m using GenerateBlocks, but which scenario is also for every other plugin that adds it own button block.
In this case GenerateBlocks introduces a button block with the css selector
gb-button
, but it doesn’t inherits the styling from GeneratePress theme because it doens’t have abutton
css class on it. And copy-ing the styling and including it myself through my own style.css kind of defeats the purpose of setting it through the Customizer options. If I you change it there, you have to change it manually there.Yes, I could manully add the
button
css class via the advanced part to the block, but then I (my clients) has to do this for every button block. I want to keep it simple and don’t want to repeat myself. Everything that I have to explain as an extra is an extra barrier to a headache free editing experience.So I would like to be able to add a css selector to this part where the styling of a button it generated https://github.com/tomusborne/generatepress/blob/master/inc/css-output.php#L398
But I don’t that’s possible, or am I missing somthing?Kind regards,
Jaime Martinez!
June 10, 2020 at 3:18 pm #1322768TomLead DeveloperLead DeveloperHi Jaime,
You could tell GenerateBlocks to use the GP styles as its default:
add_filter( 'generateblocks_defaults', function( $defaults ) { $color_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_color_defaults() ); $defaults['button']['backgroundColor'] = $color_settings['form_button_background_color']; $defaults['button']['backgroundColorHover'] = $color_settings['form_button_background_color_hover']; $defaults['button']['textColor'] = $color_settings['form_button_text_color']; $defaults['button']['textColorHover'] = $color_settings['form_button_text_color_hover']; $defaults['button']['paddingTop'] = '10'; $defaults['button']['paddingRight'] = '20'; $defaults['button']['paddingBottom'] = '10'; $defaults['button']['paddingLeft'] = '20'; return $defaults; } );
That should make it so every button you add from now on uses the GP Customizer settings, and they *should* automatically update if you change them in the Customizer.
Let me know π
June 11, 2020 at 12:06 am #1323071Jaime MartinezHi Tom, Thought because it’s touching a whole different codebase I should also separate the tickets.
Will dive into to code after the weekend. I now do get the concept that al the code will be written to the external CSS.
I 200% appreciate you taking the time!
Ciao!
June 11, 2020 at 9:43 am #1323936TomLead DeveloperLead DeveloperNo problem! Hopefully the above accomplishes it perfectly π
December 11, 2020 at 7:17 am #1576177SiT TeamHi Tom,
Thanks for this solution, this did have me stumped for a little while. Given GenerateBlocks and GP are firmly in the same family, I do think it would be intuitive to have this behaviour as default: have the button styles that GP exposes via theme customisation drive the default colour scheme on the GenerateBlocks buttons (to be optionally overridden per-button, of course).
Thanks again, and great name.
Tom
February 20, 2021 at 11:21 am #1665904GeorgeHey Tom.
Is it possible to addborder-radius
settings to the code you provide here for a default GB button?February 20, 2021 at 2:46 pm #1666031LeoStaffCustomer SupportHi George,
This should help:
https://github.com/tomusborne/generateblocks/blob/c2aad72f6868001c6f7fa9b606cafef511eebd1b/includes/defaults.php#L231-L243Let me know π
February 20, 2021 at 3:07 pm #1666050GeorgeWhaoo, everything is in there! Page saved, thanks, Leo!
February 20, 2021 at 3:34 pm #1666063LeoStaffCustomer SupportNo problem π
September 3, 2021 at 5:03 am #1917592EaydmanHi,
This really helped me a lot. I do not know why it has taken me so long before I have seen this post!This should be added to the Documentation, and the link that @Leo linked to Github
It’s really nice to finally be able to add some standard styles to the GenerateBlocks!
September 3, 2021 at 5:43 am #1917628DavidStaffCustomer SupportWe’ll be adding default styles to GB in the future, so code shouldn’t be required.
And this topic is one of those where it crosses the support boundaries… its more a GB forum thing then it i a GP thing πGlad you found it helpful though!
January 8, 2022 at 12:17 pm #2073670ChrisHey there!
Is there already a way to apply the GP style in a more convenient way to the GB button?
If not: Any chance to also apply the font settings not only the colors?
Thanks a lot π
Cheers
ChrisJanuary 8, 2022 at 12:26 pm #2073675LeoStaffCustomer SupportCan you open a new topic for your question?
Thanks!
March 3, 2023 at 8:01 pm #2554770GregIt would be nice if GenerateBlocks used the colors from GeneratePress’s color settings in the Customizer. It’s confusing now how a random color is chosen. The code Tom provided above could simply be added to GP so that those settings make sense.
-
AuthorPosts
- The topic ‘Add custom CSS selector to the button selector’ is closed to new replies.