If you like me, you most likely use a lot of the same functions in WordPress each time you create a new theme. Functions for adding theme support or enqueuing files are part of every theme developers toolkit. Recently while looking into CSS reset / normalize files I started thinking about creating a functions.php reset file.
There are so many functions it is likely you either already have your own custom prefilled functions file or run the risk or forgetting to add functions.
I decided to go over my own reset functions.php file and compare them with 40+ free WordPress themes. I quickly realized the idea of a global reset functions.php file was doomed to fail. Each site is different with unique requirements. This leads theme developers too often enable as many options as possible.
My goal was the opposite. I wanted to enable only the bare minimum while removing anything I was not using.
In this article, I’m going to share my reset functions file and briefly go over what each function is doing.
I start by removing what I don’t need from the wp_head function. Most important is removing the WordPresss version information. WebDesignViews has a great article that explains in details what each function does and how to remove them. Make sure to double check if you actually use the function before removing it.
Add Theme Support
WordPress comes with a ton of features but often you have to specifically enable support for certain features. I actually prefer this approach when creating new themes over enabling everything by default and having to remove a lot of unwanted code.
Remove ?ver jQuery
Ever view your page source and notice a lot of your CSS and jQuery end with a ?ver= query? Removing query strings from URLS will help to ensure static resources get cached. Adding this function to your functions file will help cache those files resulting in better performance.
Custom Login Error Message
By default when logging into WordPress with the incorrect details WordPress will actually tell you which part of your username / password combo was incorrect. Enter the wrong username and WordPress will return ‘Error, invalid username’. Login with the wrong password and WordPress will return ‘Error, password is incorrect’. Bruteforce hack attempts can try different usernames until it gets the password incorrect message, confirming they now know your username. To get around this simply change the login message to always be the same message.
Add Shortcode Support to Widget Areas
Shortcodes provide an easy way to embed custom functionality to your website. Unfortunately, by default WordPress sidebar widgets don’t accept shortcodes. Adding this line to your functions file will enable shortcode support in WordPress widget areas.
Loading CSS or JS to your theme should always be done using the wp_enqueue functions. This includes your style.css, a required file for every WordPress theme. This means at very least you’d need to enqueue your style.css file.
As mentioned previously WordPress has a lot of features. I tried to strip this down to the absolute bare minimum, realistically though you going to want to add menus, sidebars etc.
Final Reset Functions.php File
Hopefully, this has helped you, feel free to add your thoughts and suggestions for what should be included in a reset functions.php file. Below is everything together excluding the honourable mentions.