Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 6 • Advanced Theme Usage 155


A theme option page is a page in the WordPress admin interface containing information or
options for your theme. You create it by adding code to your theme’s functions.php file and
actually building the whole thing from there. Theme option pages have been around for quite
some time.


The specific options that will be available in your theme options page depend on the kind of
theme you’ve built. Some themes let the user alter the design by changing default font sizes
and similar elements, whereas others let you save custom code that will be outputted some-
where in the theme through action hooks. Either way, you should make sure that you know
why you may want an options page and what you need it to do. This means that you have to
sit down and figure out what option settings make sense for your theme and build the option
page from that. This will of course vary a lot from theme to theme. Some themes might
benefit from font options, whereas others might need a feature to show or hide the sidebar via
a setting on the option page.


Theme option pages are created using the Settings API (http://codex.wordpress.
org/Settings_API), which is covered in the next chapter.


THEME CUSTOMIZER OR THEME OPTIONS?


It might be tempting to add a bunch of settings to your themes, either by cramming them into
the Theme Customizer or by offering a theme options page. I urge you to reconsider and to
limit the options to only the truly necessary ones because the world does not need more
bloated themes with more options than you could possibly want or need — or than the design
warrants.


Consider usability. There are themes with tons and tons of theme options, which might sound
like a good idea at first glance. After all, with all those options, you should be able to do
whatever you like, right? Although that might be true, chances are that the theme code itself
has gotten a bit bloated, but just as important, the end user might have a hard time getting a
grasp of the options. If there are too many items to choose from and if some combinations
just work out poorly (which is often the case with font and color settings, for example), then
what’s the benefit of having all those theme options? Keep the theme options to a minimum is
my advice — your end users will thank you.


That being said, using functions.php is great for small options settings. More advanced things
should be handled outside, by calling other files or in a plugin. It is all a matter of what you
want to do, so the only really good advice here would be that you have to consider if you’re
executing your actions the right way, and if you can, move the code (or at least parts of it)
somewhere else if your functions.php file is growing too much.


Then there’s the choice between a dedicated theme options page and the Theme Customizer.
The latter is a given for visual settings, as you can offer a live preview of the settings, as well as
reload the preview should you need to. A good rule is that all visual settings should be in the
Theme Customizer, and other settings might warrant a theme options page. That does pose

Free download pdf