QUICK TIP - PHP How To Create A WordPress Plugin
- 1. QUICK TIP - How To Make Gold Miner Game With Unity 2D
- 2. QUICK TIP - Create a play bot T-Rex in Chrome – Hardcode version
- 3. QUICK TIP - Python – Building a Virtual Assistant Robot With 50 Code Lines
- 4. QUICK TIP - How Do You Understand about Hi-Res Audio?
Whereas themes modify the look of your website, plugins change how it functions. With plugins, you can create custom post types, add new tables to your database to track popular articles, automatically link your contents folder to a “CDN” server such as Amazon S3… you get the picture.
Theme Or Plugin?
If you’ve ever played around with a theme, you’ll know it has a functions.php file, which gives you a lot of power and enables you to build plugin-like functionality into your theme. So, if we have this functions.php file, what’s the point of a plugin? When should we use one, and when should we create our own? The line here is blurrier than you might think, and the answer will often depend on your needs. If you just want to modify the default length of your posts’ excerpts, you can safely do it in functions.php. If you want something that lets users message each other and become friends on your website, then a plugin would better suit your needs.
The main difference is that a plugin’s functionality persists regardless of what theme you have enabled, whereas any changes you have made in functions.php will stop working once you switch themes. Also, grouping related functionality into a plugin is often more convenient than leaving a mass of code in functions.php.
Creating Our First PlugIn
To create a plugin, all you need to do is create a folder and then create a single file with one line of content. Navigate to the
wp-content/plugins folder, and create a new folder named
awesomeplugin. Inside this new folder, create a file named awesomeplugin.php. Open the file in a text editor, and paste the following information in it:
<span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token comment">/*
Plugin Name: Awesomeness Creator
Plugin URI: http://my-awesomeness-emporium.com
a plugin to create awesomeness and spread joy
Author: Mr. Awesome
Author URI: http://mrtotallyawesome.com
<span class="token delimiter important">?></span></span>
Of all this information, only the plugin’s name is required. But if you intend to distribute your plugin, you should add as much data as possible.
With that out of the way, you can go into the back end to activate your plugin. That’s all there is to it! Of course, this plugin doesn’t do anything; but strictly speaking, it is an active, functioning plugin.
When creating complex functionality, splitting your plugin into multiple files and folders might be easier. The choice is yours, but following a few good tips will make your life easier.