Best practice to call a function from a button-link?

Question

I am developing a WordPress website where I have to link a button to a function inside the functions.php file. Meaning that when someone clicks on a certain button, this will trigger a call to a specific function.

I have read about various ways to approach this:

By creating a link acting as a button:

<a href="?action=linked_function" class="button btn btn-primary">Click to call function</a>

Or a form submission:

<form action="functions.php" method="post">
    <input type="submit" value="Call function" />
</form>

Others suggest using ajax for this case, although I don’t really care if the page has to reload after the function call or if I have to redirect the user to the previous page.

I am wondering though what are the best and most importantly safest options to develop this.

Any suggestions?

Thanks!

0
, , vsapountzis 3 months 0 Answers 45 views 0

Leave an answer