Get the current WordPress URL

In some cases, it may be necessary to get the current WordPress URL of where the user is currently browsing or visiting a web page to pass that URL in a particular PHP function.

How do I get the current URL in WordPress?

The following function is useful to getting exactly the current WordPress URL, depending on where we are browsing on the website. If we are currently on a category subpage, the function output could be, for example: https://domain.com/subcategory/.

How do I get the current URL including the parameters?

To get the included URL parameters as well, we need to modify our function. This can be useful when we are on the search page of WordPress. In this case, the function output would be, for example, https://domain.com/?s=searchterm. A helpful function would be the following:

With these simple PHP functions, you can easily get the current WordPress URL including the parameters wordpress_wp_current_url_with_parameter(); or without them wordpress_wp_current_url();.

Get the current WordPress URL Score: 5 / 5 (2votes)