Detailed description of how to use the function for adding and executing actions in WordPress, detailed description of the wordpress_PHP tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.