0

我想在 wordpress 上创建自定义函数?测试功能如下

function test() {

    echo "Welcome";
} 

以及我们如何将这个函数转换为 wordpress 以及我们如何调用这个函数?

4

2 回答 2

1

Put it in functions.php in your theme. You can then call the function from anywhere in your theme. You can have the function only be called on certain events by adding it as an action to a hook.

For example this would call the function whenever you save a post:

add_action( 'save_post', 'test' );

See the list of action hooks.

于 2013-08-16T12:24:20.910 回答
0

在你的主题functions.php中添加你的功能

function test() {

    echo "Welcome";
}
add_action('init','test');

有关更多详细信息,请参阅 codex 操作挂钩

于 2013-08-16T15:30:29.413 回答