Custom hook add action in Wordpress
I am developing a plugin but I have a trouble because I don't get hook an action to a function and show the content. I am noob developer Wordpress Plugins so sorry if i do stupid stuff. My plugin starts in page1.php and when I press a submit button to page2.php, I have a function which I want hooking, but I've tried this add_action and didn't work and I don't know which tag is the correct, if i need add some more or what can be happenning. I read several times the documentation and I've tried somethings as I said but nothing. All help is welcome, thanks in advance.
//page2.php
function testFunction(){
echo "hello";
}
add_action('page2_page', 'testFunction');
add_action('init', 'testFunction');
Wordpress has built in actions, like init
, which allow you to hook code in certain places. However, page2_page
is not a built in action. Therefore, to use it, you would have to add the code do_action( 'page2_page' );
wherever you want your code to be called. Basically, that will run all of the code that has been hooked to the page2_page
tag.
Having said that, using custom actions might be an incorrect/unnecessarily complicated way to achieve whatever you're trying to do. Clicking a button and then having more content appear without reloading the page requires a Javascript implementation.
链接地址: http://www.djcxy.com/p/57352.html上一篇: 删除使用function(){...} wordpress定义的操作
下一篇: 在Wordpress中自定义挂钩添加动作