1
votes

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');
1
What is your 'page2_page' pointing to? You may first, start by troubleshooting, hooking your function to an existing predefined location by WordPress. You can do so by editing your initial hello.php and hook your function to the admin_notices area of the dashboard, then, enable it (the Hello Dolly plugin); you should see hello printed in the notification area of your dashboard. BTW: did you registered your plugin as expected? What was your approach?nyedidikeke

1 Answers

1
votes

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.