[ad_1]
I am using the snippets plugin to run the code below to capture the URL, and it works everywhere except after the form submits (I use elementor):
`function get_full_url_with_params() {`
`$url = home_url( add_query_arg( null, null ) );`
`return $url;`
`}`
`add_shortcode(‘full_url_with_params’, ‘get_full_url_with_params’);`
Once the form submits, the above code returns “https://opentech.electronicsforu.com/wp-admin/admin-ajax.php”
What gives?
[ad_2]
The form is sending an AJAX request on submit. You didn’t give enough context as of where this shortcode is used, but I assume the content of the shortcode is updated with AJAX as well since it’s returning that link. So you could probably try something like this:
function get_full_url_with_params()
{
if (wp_doing_ajax() && wp_get_referer()) {
return wp_get_referer();
}
$url = home_url(add_query_arg(null, null));
return $url;
}
add_shortcode(‘full_url_with_params’, ‘get_full_url_with_params’);