Capture full URL ends up capturing admin Ajax instead of the URL in the address bar. Could someone help solve for this?

[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]
1 Comment
  1. 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’);

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer