Why do we use this type of thing in wordpress? Can anyone explain it to me please? Why do we use init in wordpress functions? Or, what is init
?
Leave a Reply
You must be logged in to post a comment.
Why do we use this type of thing in wordpress? Can anyone explain it to me please? Why do we use init in wordpress functions? Or, what is init
?
You must be logged in to post a comment.
Add action is used instead of hard-coding a function into WordPress. The benefit to using add_action is that you allow core wordpress functions to keep track of what has been added, and by doing so, can override previously added functions by de-registering them later on.
For example:
You download a plugin with a defined action/method named
You need to override the crappy function with your own:
By doing this you can copy the original method and customize it without changing the original files. This is very useful with plugins so that you can update them later on without losing your changes.
USAGE:
add_action( $hook, $function_to_add, $priority, $accepted_args );
Parameter:
$hook
(string) (required) The name of the action to which $function_to_add is hooked. Can also be the name of an action inside a theme or plugin file, or the special tag “all”, in which case the function will be called for all hooks)
Default: None
INIT HOOK:
Runs after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or $_POST triggers.
For example, to act on $_POST data: