While theme functions are quite powerful, they aren't very portable. If you ever wanted to switch themes, you would have to copy all your essential functions from one theme to another. There's another option: many of the theme functions you've seen throughout this book could become plugins. Plugins offer much better control over functions, since you can activate and deactivate them as needed. The plugin manager also provides some safeguards, since plugins containing errors will fail to activate, whereas errors in a theme functions file will affect your site immediately. You can do any number of things with plugins: modify or replace existing functions (filters), add your functions in predetermined locations (actions), create new template tags and shortcodes, and more.
Throughout this chapter, I'll show you examples from two of my plugins, Next Page and Dashboard Notepad. You saw Dashboard Notepad in the previous chapter; it's the plugin that adds a textarea for taking notes on the Dashboard screen. Next Page fills in a gap in the WordPress template tags: the previous and next post navigation tags work only for posts, not for pages. Next Page provides template tags and shortcodes for page navigation that work just like the post navigation. You can find the most current versions of these plugins at WordPress Extend. I'll begin by showing you simplified versions of the various functions, and I'll gradually add complexity as we go through the chapter.
Was this article helpful?