-
TWarrior
Hello,
I want all H2 on a specific page (or block) to have a certain style, without having to assign the style individually each time I create a new H2 tag.
Is this possible?
-
Hi there,
theres a few ways to do this.
Option 1 – Use Global Styles and local Patterns.
1. assign a Global Style to the H2 Headline block
2. Save the block as Pattern, make sure to uncheck the Sync option.
This method is my preferred method, as you can quickly add the pattern using a
/keyboard shortcut with the global style already attached. It takes no longer then adding a new H2 Text block.Option 2 – Global Style Container Block targeting a H2 selector,
1. create a Global Style for a Container Block and give it a name eg.
has-custom-text
2. before adding the styles, add a +NEW selector:
https://learn.generatepress.com/blocks/block-guide/style-selectors/#generateblocks-pro-selectors
2.1 in the selector field type:h2
You will see the selector looks something like this:.has-custom-text h2
2.2 now apply the styles which will affect any H2 inside the container.
3. Add the global style to any container you want to apply it to.Option 3 – Custom CSS using a GP Hook Element to apply to specific pages.
1. in Appearance > Elements -> Add New –> Hook.
2. Set the Priority to1000
3. in the Hook element add your CSS wrapped in<style>tags eg.<style> h2 { /* add your styles here */ } </style>4. set the Display Rules Location to where you want to apply the styles
Let us know if you need any more info on any options
-
TWarrior
Thank you very much for such a detailed response.
The problem here is something else. In the world of web design, especially in WordPress, developers and designers forget that websites, once delivered to the client, are managed by ordinary people.
Normal people who can barely tell the difference between a paragraph and a heading.
People who go crazy trying to use the Gutenberg block editor…
They are normal people who just want to “write and publish.”
Proof of this is that the “classic editor” plugin is the fourth most installed plugin in the entire WordPress repository, with 9 million installations.
It’s a mindset problem, which we see in other aspects of WordPress, such as the fact that by default there is no Web Manager role (you are either an Administrator with all privileges, or you become an Editor who can’t even add a user).
Returning to the topic at hand, in this case we need the user to be able to apply the desired format simply by adding an H2 block (in the block editor, only a few blocks such as “paragraph,” “heading” etc. are enabled for them).
Your option 2 works perfectly. Thank you.
PS 1: I really liked your option 1 and I’m saving it for when we’re designing the website ourselves 😉
PS 2: And option 3 was very ingenious!
-
Super happy to hear that. Glad to be of help!
- You must be logged in to reply to this topic.