The Must Have for WordPress
The Must Have for WordPress
×
  • Home
December 5, 2019
PHP WordPress

Get the current WordPress URL

by Martin Jost
No comments
1 min Reading Time
1.82 K Views
5 Score
2 Likes
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp

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();.

Last updated: December 5, 2019

Get the current WordPress URL Score: 5 / 5 (2votes)
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp
The Author
Published by
Martin Jost

View all posts by Martin Jost

Related Posts
S
WordPress Set custom WordPress post format for custom post type

If you’re working with custom post types in WordPress, you may have noticed that all post ...

Read More
C
PHP Convert HEX color to RGBA color code in PHP

While working with theme or plugin options, in some cases we need to convert a hex (hexadecimal) ...

Read More
C
PHP Customize the default WordPress Image Compression

WordPress uses its own compression for images that are uploaded directly into WordPress. This ha ...

Read More
Read more
C
Previous Post
Compress files with Gzip in PHP
U
Next Post
Use PHP to remove certain characters or words from a string
Leave a Reply Cancel reply

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

  • Imprint
  • Privacy Policy
© 2016-2023 - wphave - The Must Have for WordPress
Login

Lost your password?

RequiredEssential cookies enable basic functions and are necessary for the proper functioning of the website.
  • Name: Cookie Status
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user's web browser allows cookies.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookie_status
  • Duration: 1 Minute
  • Name: Cookie Consent
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user agrees to allow opt-in cookies or not.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookieconsent_analytics, cookieconsent_marketing, cookieconsent_status
  • Duration: 1 Year
  • Name: Like Button
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already gave a like for a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): like_btn_{POST_ID}
  • Duration: 21 Days
  • Name: Post Rating
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already rate a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): rating_{POST_ID}
  • Duration: 7 Days
AnalyticsStatistics cookies collect information anonymously. This information helps us to understand how our visitors use our website.
  • Name: Google Analytics
  • Provider: Google LLC
  • Purpose: Google cookie for website analysis. Generates statistical data on how the visitor uses the website.
  • Privacy Policy: https://policies.google.com/privacy
  • Cookie Name(s): _ga, _gat, _gid
  • Duration: 2 Years