Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report