The difference between add_action()
and add_filter()
is semantic not technical, except that a filter expects a returned value and an action does/will not.
The question is whether contact_form_send_email()
needs to be called-at /hooked-to init
.
If not, you can define your filter in the template with apply_filters()
, and then hook to it to run your function and return a value to it.
In template page:
$some_variable="some value";
$some_variable = apply_filters('my_filter_hook', $some_variable);
In functions.php
add_filter('my_filter_hook', 'contact_form_send_email', 10, 1 );
function contact_form_send_email( $some_variable ) {
//do stuff
$some_variable="some new value";
return $some_variable;
}
To help determine where you need to hook, this Actions Reference can be useful. Scroll down and you will see some template specific hooks as well.