Describes how to use the functions for adding and executing actions in WordPress. The following describes how to use the function for adding and executing actions in WordPress. the wordpressadd_action () (add action) add_action () function is used to mount a function to the action hook. Usage details: how to add and execute functions in WordPress.
Add_action () (add action)
The add_action () function is used to mount a function to the action hook.
Usage
add_action( $tag, $function_to_add, $priority, $accepted_args );
Parameters
$ Hook
(String) (required) name of the action of the mounting function.
Default value: None
$ Function_to_add
(Callback function) (required) mount the function. enter the function name in string format.
Default value: None
$ Priority
(Integer) (optional) priority of action execution. the smaller the value, the more advanced it is to be executed.
Default value: 10
$ Accepted_args
(Integer) (optional) The callback function receives several parameters.
Default value: 1
Return value
(Boolean) always returns True.
Example
Attach a function to the wp_head action and print out some items in the head tag.
function Bing_wp_head_test_print(){ echo '
';}add_action( 'wp_head', 'Bing_wp_head_test_print' );
Others
This function is located in: wp-uplodes/plugin. php
Do_action () (execution action)
Do_action () is used to execute action Hooks. The difference between do_action () and apply_filters () is that there is no return value. simply, the function attached by the plug-in or theme developer is executed in a specific place, it usually exists on a special node or event (for example, when loading a topic template or publishing an article ).
Usage
do_action( $tag, $arg... );
Parameters
$ Tag
(String) (required) name of the action to be executed.
$ Arg
(Mixed) (optional) additional parameters will be passed to the called function. you can add unlimited parameters. for example, the save_post action is triggered when saving the article, the id of the saved article can be put in, and the callback function can perform operations based on the article id.
Return value
None
Example
Function func () {echo 'test';} add_action ('test', 'func'); do_action ('test ');
Screen printing:
Test
For more information, see apply_filters (): http://www.endskin.com/apply_filters/.
Others
This function is located in: wp-uplodes/plugin. php
Articles you may be interested in:
- Tips for customizing the background management interface color scheme in WordPress
- Implement function parsing for sending http requests in WordPress
- How to set the default content in the WordPress article editor
- PHP functions used to create and retrieve sidebar in WordPress
The add_action () (add action) add_action () function is used to mount a function to the action hook. Usage...