When using WordPress themes, the compatibility and security of the scripts are sometimes taken for granted and ignored by a lot of people. But how sure are you that your third party scripts are compatible 100% with WordPress and secure, with no holes that might expose you?
But what does being compatible with WordPress mean? Aren't all themes compatible because they work once installed? How can I check if I am using badly written scripts?
We are going to try in this quick tip to cover some of these answers and help you understand how to check your WordPress website for weaknesses and loose ends because of the plugins or themes you are using.
Note: This quick tip is also addressed to developers that are writing WordPress plugins or themes.
Checking for Compatibility, Fast and Easy
Before we look into a slightly detailed idea of how to check your theme compatibility with WordPress, we are going to look at a very easy way to identify any bugs, deprecated functions or other incompatibilities your theme might suffer from.
Use Free Plugins!
"All of these plugins are used by the theme review team on WordPress.org"
There are three free plugins that you can use in order to check your theme's code compatibility with WordPress and to look for any bugs you might have missed:
A free plugin used mostly by developers, that helps you check if your theme is compatible with all the latest WordPress standards. This plugin, just like the other two, is used by the WordPress.org Theme Review Team in reviewing the submitted themes on WordPress.org. Among its features it also has the option of enabling Trac formatting so the error messages can be just copied and pasted directly into a Trac ticket for the theme (for those using Trac for feedback on code, this is a good feature).
This plugin, also free, also from WordPress.org and also for developers, it is an incredibly useful plugin for checking deprecated functions, files and function arguments that the active theme might be using. This allows you to make sure you are using all the newest WordPress core functionality of your current installed version. Even more helpful, it logs incorrect function usage for all WordPress 3.1+ installations.
This one's cool and useful. It not only does an extensive debugging of your theme and outputs the result in your footer but also checks the current loaded page to see if it validates.
So there you have it, everything you need to easily get started on theme development if you are a developer or just to check your currently installed theme for compatibility, you just install these plugins and have fun watching your theme react. I'm not going to go into detail with the functionality of each plugin as there is no point in that for the purpose of this tutorial.
A Little More Technical
In this part we are going to take a look at what to look for and check when building a theme so that you might get a lower error count in your logs when checking the final result with the previous plugins.
Say "No" to Deprecated Functions
Sometimes you just are used to doing stuff a certain way, other times you find an online tutorial that has exactly what you need and you don't know that it might be outdated, or maybe you just search for how to code something in your theme and you don't notice that the function even though it is in the codex and is well documented, it is deprecated and there's another way to achieve your goal, a more compatible way.
How do you know the function you want to use is deprecated? Well, the most obvious and quick way, if you check the codex for it, you will notice a big red colored text message telling you it's deprecated on the top of the page like in the next example picture:
There are many deprecated functions in WordPress, if you want a complete updated list of all of the deprecated functions, you can find it on the Deprecated Functions page of the Codex.
Code Quality and Integration
This part is mostly for developers. No matter what you are doing, you must do it right, and here I am referring to using the right code in the right place. If you want a category, tag, comment section, date, author etc. elements integrated into your theme for example, make sure you are using the best approach that you can use by doing this in WordPress. Don't re-invent the wheel, try to find out how something is done and do it the right way, and most importantly watch out for easy integrations like script and style registering and enqueueing, generating URLs to your theme, working with files, pictures and data from the database. WordPress has all the tools you need to help you do most, if not all, of your required theme functionality.
These are just a few examples of approaches you need to look out for when coding. There are plenty.
Header, Footer, Sidebar
Some things might seem to work at the beginning but if they are not implemented correctly, they will not work. The most important aspect of this idea in a theme's functionality are the header.php, footer.php, and to a lesser extent sidebar.php files, that are the default header, footer and sidebar files that you normally include into your theme code. Getting to the point, if these files are not implemented correctly, your theme will not be compatible with WordPress at all, as there is necessary core functionality happening inside these files. When and if you get errors from the plugins we mentioned at the beginning, you might find your missing or bad code in one of these files.
The most important file in any WordPress theme, as it is the file that holds all the main code core functionality. This is the place where everything happens, the bakery, the "source". Here, you run all your hooks, register your scripts, create the widgets, implement everything and anything you might require in your theme. So I think it's safe to say it's the number one place to look for errors when they turn up.
WordPress has a number of functions that you might want to include in your website where they should be included.
That's a little vague, isn't it? Let's look at an example: if your websites has a blog version, and you want that blog to have all the flexibility and compatibility with WordPress, and most if not all plugins, you might want to make sure you integrate with the functionality generating that page the core features needed by WordPress or the plugins to do their magic. Things like integrating the sidebar properly, the comments section, writing the loop correctly and even generating the header and footer files is a very important part of the compatibility you should be looking for.
WordPress development has some rules and approaches, make sure you know what they are when implementing anything and make sure you are not missing something important that might make your theme incompatible or insecure. Don't forget to test, re-check and stay up to date with all the updates that the new WordPress versions bring.