Detailed description of how to add and execute actions in WordPress using the wordpress_php tutorial

Source: Internet
Author: User

A detailed description of how to add and execute actions in WordPress, using the method of WordPress


Add_action () (Add action)
The Add_action () function is used to mount a function onto an action hook.

Usage

Add_action ($tag, $function _to_add, $priority, $accepted _args);

Parameters

$hook

(string) (must) the action name of the Mount function.

Default value: None

$function _to_add

(callback function) (must) mount the function, directly fill in the function name in the form of a string.

Default value: None

$priority

(integer) (optional) The priority of the action execution, and the smaller the number, the first is 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 something in the Head tab.

function Bing_wp_head_test_print () {  echo '
 
   ;} Add_action (' Wp_head ', ' bing_wp_head_test_print ');

Other

The function is located at: wp-includes/plugin.php

Do_action () (Perform action)
Do_action () is used to execute an action hook, and the difference between it and apply_filters () is that there is no return value, simply that the plug-in or the theme developer-mounted function is executed in a particular place, Typically exist on a particular node or event (such as when you start loading a topic template or when you post an article).

Usage

Do_action ($tag, $arg ...);

Parameters

$tag

(string) (must) the name of the action to be performed.

$arg

(mixed) (optional) additional parameters, will be passed to the function of the call, you can add unlimited, such as saving the article when the trigger Save_post action, you can put the ID of the saved article in, let the callback function according to the article ID to operate.

return value

None

Example

function func () {  echo ' Test ';} Add_action (' Test ', ' func ');d o_action (' Test ');

Screen printing:

Test

More references to similar apply_filters (): http://www.endskin.com/apply_filters/

Other

This function is located at: wp-includes/plugin.php

Articles you may be interested in:

    • Tips for customizing the background Management interface color scheme in WordPress
    • Implementation of correlation function parsing for sending HTTP requests in WordPress
    • Ways to set default content in the WordPress article editor
    • PHP functions for creating and getting sidebar in WordPress

http://www.bkjia.com/PHPjc/1086647.html www.bkjia.com true http://www.bkjia.com/PHPjc/1086647.html techarticle a detailed description of how to add and execute actions in WordPress using the method, detailed WordPress 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.