WordPress Plugins

A plugin is a piece of PHP code that adds a feature to WordPress. Contact forms, SEO tools, online shops, backups, security, caching and sliders are all done by plugins. Plugins use WordPress hooks, so they do not change the core files, and you can add or remove them at any time.

Install a plugin

1. From the dashboard (search)

  1. Go to Plugins > Add Plugin.
  2. Search for the plugin by name or by the feature you need.
  3. Click Install Now, and then Activate.

2. Upload a zip file

For a paid plugin or your own plugin: Plugins > Add Plugin > Upload Plugin, choose the zip and click Install Now.

3. Copy the files manually (FTP)

Unzip the plugin and upload its folder to wp-content/plugins. Then activate it from Plugins > Installed Plugins. This way is needed when the dashboard upload does not work.

4. With WP-CLI

Terminal output

$ wp plugin list –fields=name,status,version
name status version
akismet inactive 5.7.2
hello inactive 1.7.2
$ wp plugin install classic-widgets –activate
Installing Classic Widgets (0.3)
Downloading installation package from https://downloads.wordpress.org/plugin/classic-widgets.0.3.zip…
Using cached file '/tmp/wpcache/plugin/classic-widgets-0.3.zip'…
Unpacking the package…
Installing the plugin…
Plugin installed successfully.
Activating 'classic-widgets'…
Plugin 'classic-widgets' activated.
Success: Installed 1 of 1 plugins.
$ wp plugin list –fields=name,status,version
name status version
akismet inactive 5.7.2
classic-widgets active 0.3
hello inactive 1.7.2
$ wp plugin deactivate classic-widgets
Plugin 'classic-widgets' deactivated.
Success: Deactivated 1 of 1 plugins.
$ wp plugin delete classic-widgets
Deleted 'classic-widgets' plugin.
Success: Deleted 1 of 1 plugins.

Activate, deactivate and delete

ActionWhat happens
ActivateThe plugin starts running. WordPress saves its name in the active_plugins option
DeactivateThe plugin stops, but its files and data stay
DeleteThe files are removed. Most plugins also remove their data (check the plugin settings)

The active plugins are saved in the database as a list. Here is how it looks:

Terminal output

$ wp plugin activate akismet hello
Plugin 'akismet' activated.
Plugin 'hello' activated.
Success: Activated 2 of 2 plugins.
$ wp option get active_plugins –format=json
["akismet\/akismet.php","hello.php"]

How a plugin works inside

A plugin is a PHP file with a special comment at the top. WordPress finds all the files in wp-content/plugins and reads this comment:

Terminal output

$ head -12 wp-content/plugins/hello.php
<?php
/**
* @package Hello_Dolly
* @version 1.7.2
*/
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.7.2
Author URI: http://ma.tt/

When the plugin is active, WordPress loads the file on every request. The plugin then uses hooks to run its code at the right time. You will build one in Create a WordPress Plugin.

Must use plugins

The files in wp-content/mu-plugins are loaded always, before normal plugins. They cannot be deactivated from the dashboard. Hosts and agencies use them for the code which must never be turned off.

How to choose a safe plugin

  • Check the active installs, the rating and the reviews on the plugin page of WordPress.org.
  • Look at Last updated. A plugin without an update for more than a year or two can be risky.
  • Check that it is tested with your WordPress version, and with your PHP version.
  • Read the support forum: are the problems answered?
  • Install only what you need. Every plugin adds some code and some risk.
  • Never use a pirated copy of a paid plugin.

After you install

  1. Do the settings of the plugin (they are often under Settings or in a new menu).
  2. Keep it updated. See Backup and Update.
  3. Remove it when you do not need it.
Note: If the site breaks after a plugin activation, rename the plugin folder with FTP. WordPress will deactivate it, and you get the dashboard back. Next: WordPress Top Plugins List.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Write a plugin which adds a text to the footer
Interview Questions & Answers
What are the popular plugins in WordPress for SEO?
How to create a WordPress global options page?
How to create a WordPress plugin from scratch?
What is a plugin in WordPress? How is it different from a theme?
What is a must-use plugin (mu-plugin) in WordPress?