I've read too many times this kind of code to add a link in plugin admin page:

function plugin_add_settings_link( $links ) {
$settings_link = '<a href="options-general.php?page=plugin_name">' . __( 'Settings' ) . '</a>';
array_push( $links, $settings_link );
return $links;
$plugin = plugin_basename( __FILE__ );
add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' );

What this piece of code doesn't answer is my question: how to have the link do what I want it to do.

options-general.php?... or whatever doesn't tell me how from a single link I can trigger a single function in my plugin.

if in my plugin file I have

function my_plugin_function() { ... }

I want the user to be able to click a link <a href="???">Click here</a> so my_plugin_function get fired.

How to do so?

Is there some url formatting which does this trick (something wich may looks like this "plugin-call.php?action=my_plugin_function&nonce=d56f654a465e4&notarealworldexample=donttellmeaboutit")?


Apparently I have to start a bounty to have this question answered.
The question being "How from the admin panel can I have a link trigger a function from my plugin (with an (async)postback ?)?" I think it deserves 5 billions points.
I don't have those and a mere 50 points for such a complex question would feel like a joke.

So here it is "IOU points". The one who answer the question can have it.

  • A link is a link, it bring you to the link address. I don't understand what you mean with "meaningful link". You will to think in what you want to do and explain it better: for example, "trigger a function in admin when some conditions are met", "create a configuration page for my plugin", etc.
    – cybmeta
    Mar 17, 2015 at 13:01
  • I want to trigger a custom function. Mar 17, 2015 at 13:05
  • Could this be what I'm looking for while still being the right way to do it: wordpress.stackexchange.com/a/67916/57112 ? Mar 17, 2015 at 13:32

1 Answer 1


Short: You can't. Php functions can't be run "straight" from a button because they run server side. You need either to set a $_POST or $_GET (so you can run the function on the page load) or use ajax/javascript.

You can find multiple answers to this question on the site already. For example this. edit: button/link, doesn't matter.

  • I know that. I'm talking about the wordpress workflow. How to format a url/a form so wordpress will trigger my function after postback (in opposition of redirecting to some intermediate webpage). Mar 17, 2015 at 13:18
  • Oh. You could add <input type="hidden" name="my_plugin_function" value="1"> to your form and then add if (isset($_POST['my_plugin_function'])) { my_plugin_function(); } in your code I think? edit: Yeah just realised you weren't using any forms... Well you should be able to do the same with url anyway.
    – jimihenrik
    Mar 17, 2015 at 13:33
  • I appreciate your help, but you'r thinking on a php perspective only while the whole box is actually wordpress. Mar 17, 2015 at 13:35
  • Okay, true. But I'm fairly certain there isn't a magic url that will fire the function for you. :/
    – jimihenrik
    Mar 17, 2015 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.