O'Reilly logo

Smashing WordPress: Beyond The Blog by Thord Daniel Hedengren

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. ANATOMY OF A WORDPRESS PLUGIN

It goes without saying that plugins are different from themes, but a lot of things concerning them share the same ground. If you simplify things, you could say that when you're adding functionality to your theme by adding code to the functions.php template file, you're actually writing a plugin.

But there is a huge difference. Themes are there to display the WordPress site, using the tools available. Plugins, on the other hand, are used when you need to extend the WordPress functionality with additional features. You should remember that, because bloating your theme's functions.php with features sometimes isn't the way to go.

In this chapter we'll look at plugins from a slightly different standpoint than we did with the themes chapters previously. The reason for this is simple: your plugin can do anything. It is basically a way for you to add whatever feature you want; compare that to doing funky stuff with a select few template tags, and you see the difference.

With plugins, it is not a matter of what you can do, it is more a question of why. So that's where we'll start.

Plugin Basics

A plugin's essentials don't differ too much from a theme's essentials. Instead of the necessary style.css stylesheet file with its theme-identifying top header, you have an aptly named PHP file with a similar header. Then you can expand by adding even more functionality outside of the main plugin PHP file if you want, just like you add template files to the child ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required