This PHP code enables you to add a CSS class to any WordPress or Genesis widget by way of your child themes functions file. This way, your class will not be removed when WordPress or Genesis is updated.
You can also target the widget by widget_name or widget_id.
You can also use the code to remove and/or replace classes.
Demo Video #
In this case, we target the calendar widget in the primary sidebar of the Genesis Sample child theme by StudioPress. When inspecting the HTML output in the source code, you can see the custom class named your-custom-class-by-name has been added to the widgets existing classes widget_calendar.
Because the code also includes a conditional tag to target the front page, the class is only added to the widget on the front page.
Works in any WordPress themes functions.php file.
Installation Steps #
There’s only 1 step :
Copy & paste the PHP code to the end of your child themes functions.php file.
Use is_active_sidebar to target specific sidebar widget areas.Subscribe for new Genesis Tutorials