Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the functions of adding and performing actions in WordPress

Shulou Source: shulou.com Published: 2022-06-03 11:07:55 10月03日 Update

This article mainly introduces how to add and perform action functions in WordPress. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.

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) the action name of the mount function.

Default value: None

$function_to_add

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

Default value: None

$priority

(integer) (optional) the priority of the execution of the action, the smaller the value, the first to be executed.

Default value: 10

$accepted_args

(integer) (optional) the callback function takes several parameters.

Default value: 1

Return value

(Boolean) always returns True.

Examples

Attach a function to the wp_head action and print something out on the head tag.

Function Bing_wp_head_test_print () {echo';} add_action ('wp_head',' Bing_wp_head_test_print')

Other

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

Do_action () (execute action)

Do_action () is used to perform action hooks, which differs from apply_filters () in that it does not return a value, but simply executes plug-ins or functions mounted by theme developers in a specific place, usually on a particular node or event (such as when you start loading a topic template or when you publish an article).

Usage

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

Parameters.

$tag

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

$arg

(mixed) (optional) additional parameters will be passed to the called function, which can be added infinitely. For example, if the save_post action is triggered when the article is saved, you can put the id of the saved article into it and let the callback function operate according to the article id.

Return value

None

Examples

Function func () {echo 'test';} add_action ('test',' func'); do_action ('test'); these are all the contents of the article "how to add and execute actions in WordPress". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Functions actions parameters characters strings articles times articles topics examples content integers hooks special things events values priorities interests names Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Apple OPPO Reno macOS