Hooks in WordPress

Hooks in WordPress

Step 2

Now we have to protect the content from hacking so that no-one can open this file directly. For this we use the following code

if (! defined(‘ABSPATH’)):

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

end if;

Where is ABSPATH Function?

Whenever we open the index file it goes to wp-blog-header then visit wp-load and template –header file after that there ABSPATH function is defined you can easily check.

Shortcut of above code

Defined(‘ABSPATH’) || die (“You can’t access this file directly”);

Never use echo directly in plugin file; we use hooks instead of these.

What is Hooks in WordPress?

In WordPress, Hooks are special functions that are defined in a particular position of WordPress. Basically there are 2 types of Hooks

  1. Action Hook: As from name clear these hooks are used to perform any action like update, delete etc. It doesn’t return any value just do their work and exit.
  2. Filter Hook: These type of hooks must return a value either null, number string, array object etc.

 Actions are functions performed when a certain event occurs in WordPress. Filters allow you to modify certain functions.

Post Your Comments & Reviews

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