Activate / Deactivate Hooks in WordPress

Activate / Deactivate Hooks in WordPress

Step 3

There are 3 Core Hooks in WordPress Plugin

  • Register_activation_hook ();
  • Register_deactivation_hook ();
  • Register_uninstall_hook ();

But we can’t use Register_uninstall_hook () instead of this we create a new file with name uninstall. php within same folder

And write the below code to delete the plugin


Defined(‘ABSPATH’) || die Plugin deleted successfully “);


Above 3 hooks has 2 parameter first is file name and second one is callback or anonymous function, while passing these parameters now plugin work smoothly as given below



* Plugin Name: Shairy Plugin

* Author: Er. Shairy Kalra

* Author uri:

* Version:1.0.0

* Description: This is the basic plugin to understand the functionality how a plugin is created



die(“You can’t access this file directly”);



            add_option(‘updateTitle’,’This is Mine Title !’);



function deactivate_option(){

            delete_option(‘updateTitle’,’This is Mine Title !’);



Now you can check from this URL; a new title is added on activation of plugin


Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *