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.36 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
C
WordPress Custom image sizes for your WordPress theme

WordPress has 5 default formats for image sizes, which are automatically created every time afte ...

Read More
C
WordPress Customize or Modify the WordPress Post Excerpt

WordPress comes with own functions, such as get_the_excerpt() or the_excerpt(), to output a shor ...

Read More
C
Database Create a connection to WordPress MySQL database in PHP

WordPress stores all the website data in a database and uses it, for example, if a certain conte ...

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-2022 - 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