How to add contact form 7 inside a custom function?

By | March 23, 2021

Here is a rough example for using contact form 7 inside a filter hook.

add_filter(
'wpcf7_validate_tel*',
static function ($result, $tag) {

// Conditional logic that used to be in the function
$url = home_url(add_query_arg(null, null));
if (!(strpos($url, ‘id’) && strpos($url, ‘form_id’))) {

// This is the original callback, now moved here.
// Assign the result back to the filter’s first argument
$result = number_field_exist($result, $tag);
}

// No matter what, we need to return something because this is a filter
return $result;
},
‘number_field_exist’,
10,
2
);

Leave a Reply

Your email address will not be published. Required fields are marked *