Categories

Featured templates

WordPress hook

Дарья Миронова July 11, 2016
No votes yet.
Please wait...

A Hook is a generic term in WordPress that refers to places where you can add your own code or change what WordPress is doing or outputting by default.

WordPress is based on the so-called Hook System. This serves WordPress, and all the extensions to involve functions in a certain place.

To put it simply, a “hook” is a certain location in the WordPress code which allows you to attach or run your own code. The word “hook” is a good description because it literally conveys the act of hooking onto something – in this case hooking your code up to the core code of WordPress.

Another way of describing WordPress hooks is that they are sort of like designated areas within the WordPress code which give you the opportunity to execute your own functions.

In WordPress there are two types of hooks – Action Hooks and Filter Hooks:

  • An Action in WordPress is a hook that is triggered at specific time when WordPress is running and lets you take an action. This can include things like creating a widget when WordPress is initializing or sending a Tweet when someone publishes a post.

  • A Filter in WordPress allows you get and modify WordPress data before it is sent to the database or the browser. Some examples of filters would include customizing how excerpts are displayed or adding some custom code to the end of a blog post.

To use the possibility of the hooks, you can use the same function as WordPress (do_action()), and you don’t have to create your own functions or methods.

In the following example function, which I put in the functions.php of the theme, of my Footer my_footer() will be a hook defined using the function do_action(). This can now be used and the hook is possible from the outside.

For example:

function my_footer() { do_action('my_footer'); }
Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket

Comments are closed.