26/04/2024 • Wordpress

Helpful WordPress Theme Development Functions

A few handy PHP functions which can help streamline your Wordpress theme development.

I’ve recently been getting to grips with WordPress theme development. While there are many excellent WordPress theme available, I’ve always favoured building websites from scratch. I’ll write about the benefits of this approach in another post, but for now I just wanted to document a few useful functions I’ve been using when developing WordPress themes.

These can be added to your theme’s functions.php file

Hide Gutenburg

Gutenburg was a massive step forward for WordPress. But that doesn’t mean it’s a good solution for everyone. My preferred method of building content managed websites is to provide my clients with ‘structured’ inputs – flexible layout options which allow for creativity whilst ensuring the pages remaind neat and tidy. For most websites Gutenburg offers too many options, making it difficult for website owners to keep their pages looking uniform.

In order to return to a ‘structured’ approach, I remove Gutenburg – returning to the standard blocks editor which is then augmented with Advanced Custom Fields. Here’s how to hide Gutenburg:

Hide Gutenburg CSS on Front End

And if you’re not using Gutenburg there’s no need to load the CSS on the front end. It’s unnecessary bloat, slowing down the site and potentially making it more difficult to write concise CSS. Here’s how to prevent WordPress loading Gutenburg’s CSS files on the front end:

Prevent CSS Being Cached During Development

Another issue I’ve regularly encountered is that of browser caching. It can be really frustrating to be developing a theme, and constantly have the browser caching CSS files, preventing your changes from being seen. I’m sure there are loads of better solutions to this, but adding rand() to the end of the theme’s version number seems to work fine. This effectivaly makes the browser see a new version of the styles.css file every time you refresh the page. Remember to remove this before launching your site.

Change Default Logo

Another helpful function makes it easy to swap the default WordPress logo on the login page. This is a nice touch, making WordPress feel slightly less generic. There are some plugins which do this, but why use a plugin when a few lines of code will work just as well (if not better!)