WordPress Theme Development Controversies and what some say can be not only wrong but hurt your site and its performance.
Just to name a few…
- Don’t add custom stuff that should be a plugin.
- Clearly separate all of the src resource files.
- Minimal Admin Options
While these controversies are opinions, here are some reasons why the above are wrong in my eyes.
First thing to point out is that the Codex for WP options shows you to make an option for each item you need.
Then use
1 |
get_option() |
to retrieve the option data.
Problem One: Most Plugin and Theme developers take this to heart and follow the Codex to the letter.
Problem Two: Because of this themes and plugins fill the database with 100’s of rows worth of options.
Problem Three: Each new option IE. get_option() causes a query if they are not loaded at the right time.
Now everyone is wondering why the site is loading so slow! Ah, get my options!
The Codex is a guide, not a template.
Your options should be in an array then saved to one row.
1 2 3 4 5 6 |
$my_options = array( 'option_1' => 'some value', 'option_2' => 'another value' ); // Add the whole thing to one row in the options table add_option('my_options', $my_options); |
Now you have your options in one serialised row instead of multiple option rows..
1 2 3 4 5 6 |
var_dump(get_option('my_options')); // Returns array 'option_1' => string 'some value' 'option_2' => string 'another value' |
Basically there is no reason to add a ton of option rows to the database, they can be in one row if they are all relevant.
This leads to the reason of adding code that could be a plugin into a theme.
Most say this is bad practice because it locks you to that theme.
Well the theme developer should offer those items in a replacement as a plugin encase you change themes. (Problem solved)
Now I am not referring to themes that package plugins with them, I’m referring to built in.
The reason for building theme in is to lower resource use.
- Options in one row with the theme options
- No extra plugin hooks, functions and files to load
- You know what is in there!
There are a ton of reasons to do this, all having to do with performance benefits
HTTP requests, I preach constant about these having an impact on a persons site load speed.
Having style.css, reset.css, fonts.css, colors.css……
IS WRONG and adds huge hits to a persons site.
For what benefit, separation. bla, comment blocks in the CSS provide the same thing with out the use of extra resources.
I see this done with javascripts also.
These files should all be minified and combined into one CSS and one JS file.
Which will provide a huge performance savings with a lot of themes out there.
Keep copies of the original files in an non-included directory for referring to.
In the end, if you combine enough resources into one object, you save on your server, sites load speed and the visitors will be happier.
On the same note, watch how many widgets you add, each one adds a query or 2 even when not used.
I actually disable them and saves like 12 queries.
WARNING: Google now has page speed built into their search and index algorithms.