Usually in my PHP apps I have a base URL setup so I can do things like this
<a href="<?php echo BASE_URL; ?>tom/jones">Tom</a>
Then I can move my site from development to production and swap it easily and have the change go site wide (and it seems more reliable than <base href="" />
.
I’m doing up a WordPress theme, and I am wondering, does WordPress have anything like this built in, or do I need to redefine my own?
I can see ABSPATH
, but that is the absolute file path in the file system, not something from the document root.
get_bloginfo('wpurl');
would be the preferred method of getting the base url of your WordPress installation. This always returns the absolute base url for the install where asget_bloginfo('url');
is for the actual blog address of your WordPress install.Yes, you can use
get_bloginfo('url')
just like that or define a constant…If you are working on a template and want the URL fragment to that theme folder, use…
You can try using
By using this can get site url like http://www.xyz.com
By using this syntax you will get url like http://www.xyz.com/contact
Yes you can get “base URL” with a simple function.
after that with
/
you can reach to any page just type the page name.You can use the built in wordpress function
site_url()
which retrieves the URL for the current site.Take a look at site_url for more details.
EX: