Archived topic
Hooks Element styling with css
3 replies · Started by Baz on November 27, 2020
I'm trying to get my head around the Hooks Element feature in GP. I usually create widget areas using the standard register_sidebar( array( function, and then use the <div class="after-entry-widget"> to style the widget area using css e.g. background-color, padding etc.
So, if I wanted to create an after entry widget area in GP, what and where would I enter some code so that I can target this area with CSS?
Finally, is there an advantage to using the Hooks Element vs registering sidebars the old-fashioned way?
Thanks.
Hi there,
To actually register the widget area, you'd want to use a regular functions file or code snippets.
Hooks are a great way to display the widget area once it's been registered.
When displaying the area, you can wrap it in a container with a class so you're able to target it with CSS.
Hope this helps!
Thanks Tom.
I thought Elements was a way to create widget areas :)
I suppose it's more suited to inserting code/snippets within certain areas/hooks of the theme. So, if you are comfortable with PHP and targeting hooks, I guess you can do without activating the Elements module.
Cheers.
If you're comfortable writing hooks and filters, then you can likely skip Elements. However, the Display Rules are very convenient, especially when dealing with multiple conditions. Sometimes it's easier to use them than write your own conditions :)