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

Get the installation URL of WordPress

by Martin Jost
No comments
1 min Reading Time
1.32 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 can be very helpful to use the WordPress installation URL for a PHP validation procedure. The following example shows how easily you can get the installation URL of WordPress by using a small PHP function.

How do I get the correct URL of the WordPress installation?

The following PHP function is helping us to figure out the installation URL WordPress. This wrapper function uses the WordPress own function get_site_url(); to do this:

The benefit of this function is that it will output the current and correct installation URL even if WordPress is running on multisite instances.

It should also be noted that we use get_site_url(); to get the currently used installation path. For example, if WordPress is installed in a subdirectory. In this case, our function would then output “https://domain.com/subdirectory/” instead of just the main domain. This is important in special cases, if several WordPress installations using the same domain name.

A common mistake is to use the WordPress get_home_url(); function instead, to get the web url of our WordPress installation. Because this function always outputs only the domain name. Even if the active installation is installed in a subdirectory.

Last updated: December 5, 2019

Get the installation URL of WordPress Score: 5 / 5 (1vote)
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
A
WordPress Add WordPress images to the RSS feed

By default, if you have enabled the WordPress RSS feed, images will not be included in the RSS f ...

Read More
G
PHP Get the current WordPress URL

In some cases, it may be necessary to get the current WordPress URL of where the user is current ...

Read More
U
PHP Use PHP to remove certain characters or words from a string

The default PHP function str_replace(); is a useful tool if we want to remove certain characters ...

Read More
Read more
M
Previous Post
Minify or compress CSS in PHP
C
Next Post
Create a connection to WordPress MySQL database in PHP
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