WordPress: How to move all your plugin code to your theme file so you think you are not actually running any plugins
In this article I am going to attempt to show you the evil of plugins in WordPress and how you can quickly and easily solve all your plugin woes without using a single plugin.
Plugins are evil!
We have all seen the news of W3 Total Cache and its security vulnerablilities, and most of us have experienced how drastically adding plugins to an application can slow it down to mindbogglingly slow speeds. Plugins are the bane of any WordPress site administrators existence. Why do we over and over submit ourselves to this horrific show, following blindly down the path of "there's a plugin for that" only to have our sites squashed by the flood of incoming users. Money is lost and tears are shed, yet it does not have to be this way! Following the simple steps outlined in this article you will not only have a site free of plugins, it just may see a performance gain leading to a massive influx of new users.
Get rid of those yucky plugins
For the purposes of this article I am going to be using the theme twentyeleven for demonstration, as it currently comes pre-bundled with WordPress.
The first thing you aught to do is open the wp-content/themes/twentyeleven directory and add a new folder called not-plugins. This folder can really be named anything, but this tutorial will refer to the not-plugins folder.
Now open the wp-content/plugins folder and copy all the contents to the new wp-content/themes/twentyeleven/not-plugins folder.
To easily load the code from the previously existing plugin file(s) lets create a file in wp-content/themes/twentyeleven/not-plugins/include.php. This file will hold links to all our not-plugin code.
Load up include.php
I am going to use a couple plugins that *gasp* I made. Now before you judge me for having created plugins remember that that happened before the era of enlightenment on not using plugins. This is only an example to help you get started without any plugins of your own anyways right? Cut a guy some slack.
Plugins have a single file that controls the loading of the plugin. generally this file is the name of the plugin with dashes instead of spaces and of the form plugin-name/plugin-name.php. This does not have to be the case as the structure is not required by WordPress ( another evil of plugins!!!! ) so you may have to open a couple files to figure it out. The main plugin file will have a comment at the top of it that looks something like:
- Plugin Name: Parent Category Toggler
- Plugin URI: http://wordpress.org/extend/plugins/parent-category-toggler/
- Description: Automatically toggle the parent categories when a sub category is selected.
- Version: 1.2
- Author: Ben Lobaugh
- Author URI: http://ben.lobaugh.net
- Original Author: Aw Guo
- Original Author URI: http://www.ifgogo.com
- Licence: GPL
Open the include.php file and add a new line for each plugin. In this example the include.php file will look like:
- require( 'parent-category-toggler/parent-category-toggler.php' );
- require( 'misspelling-reporter/misspelling-reporter.php' );
Include the include
The last remaining step is to link the new not-plugins/include.php into the theme to complete the system and provide you a bona fide no plugins needed WordPress installation.
The main theme folder should have a functions.php file. If not create it. This file will be our link. Open functions.php for editing and on the first link you should find a
tag. The line after this opening PHP tag is where we want to put the code linking the not-plugin folder to the rest of the site. It should look like:
- require( 'not-plugins/include.php' );
You done it!
Congratulations! Your site it now plugin free :D. If any pesky new plugins make their way onto your site just repeat the steps from moving them into the not-plugins folder.
Now go forth and conquer the web world!
This article is poking fun at all of the articles that have been cropping up of late that explain how to add new functionality to a WordPress site without writing a plugin. In reality all you are doing is moving the plugin code into the theme. As shown above it is the exact same code and the whole premise is absurd. Some ( many ) things are better off done as a plugin and not part of the theme. It is perfectly acceptable to run a site with many plugins running. In fact the site you are reading this on has about 30 running, and I have worked on sites with double that number. A poorly written plugin can definitely slow your site down, but the reality of it is that 60 or 1 your site would have slowed down with the bad plugin. Otherwise you will probably not notice a speed decrease. Also using the method listed above locks your plugins in at their version and you will not be able to receive updates with new functionality and security patches.
I know some people will have gotten to this point and still not understand that this is a gag article. It is not real, a hoax, something written to exaggerate an absurdity, a bit of a rant to create a cathartic atmosphere for my heart.