I ran into a problem with my widget titles in which I wanted to change the formatting of them. After searching for a while, I found a few promising solutions to my problem, but none did exactly what I wanted to do very easily. I wanted to add a <span> tag to my widget titles to format them the way I wanted them to be.
Thanks to Genesis (aff link), my job was much easier, but I had a hard time getting it to work. Here’s the code that I started off with in my functions.php file:
I couldn’t get it to work until I remembered an article I had read from WP Smith called “How to filter the Genesis sidebar defaults” in which he explained the order in which Genesis calls files. In it he explains why he develops a core functionality plugin and why it’s good idea. Call me old school, but I don’t like seeing any extra plugins that aren’t necessary, so I wanted to get this done using my functions.php file, although adding a core functionality plugin is something I will start thinking about.
Since I was trying to hook into the functions that Genesis uses and they are called into action before my ‘add_filter’ statement, it wouldn’t work. In his article, he says that even if you place it before the require_once( get_template_directory() . ‘/lib/init.php’ ) it wouldn’t work.
Being the stubborn, non-believer I am, I tried placing the add_filter( ‘genesis_register_sidebar_defaults’, ‘ozzy_register_sidebar_defaults’ ); before the call to the init.php file, and low and behold, it worked!
So my finished code was split up into two parts. One at the very beginning of my functions.php file that make the file start off like this:
and another deeper in the file that would be the function that adds the extra formatting to my widget title:
Fairly easy and straight-forward once you have a better understanding of what it is you’re really trying to do and how WordPress and the Genesis framework operate!
Have any questions or comments on changing the formatting of a widget title in Genesis? Please leave a comment below!