$my_url="my/relative/url.php";
echo site_url($my_url);
site_url() when used by itself will return the absolute path to your blog. But, if you add an argument to it, as per my example above, it will prepend the absolute path to your path. Just make sure your URL doesn’t contain a leading slash (eg: /this/may/not/work).
Finally, if you happen to have your wordpress installed in your server’s root, you can use a server-relative path (this uses the leading slash to indicate starting at the server root). So if your blog is installed at http://www.me.com/blog
then you can access your relative links safely with /blog/my_link.php
.
Related Posts:
- Change website URL without breaking links or images? WP 3.3
- Confusion about how a URL is being parsed
- Get the url of a page template without using the page slug and ID
- How to generate a list of all urls
- Edit permalink for certain pages
- cannot link a external url, present page url acting as parent url
- rebuilding/ rewriting a url to make it SEO friendly
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- After post URL change also automatically change references in posts to that new URL?
- remove “index.php” from permalinks
- How does WordPress create URLs that Apache knows about?
- Stop WordPress appending `-2` to the end of my url after i change it
- Get default permalink structure from pretty URL’s
- Get current URL (permalink) without /page/{pagenum}/
- How to get pretty URLs with add_query_arg in permalinks
- Creating custom permalink structure for languages
- Getting the Site URL Including the Front Base
- How can I store page ID in a post instead of other selected permalink?
- WordPress Permalink changes to question mark (?) in URL
- Adding another word in front of post url
- How to prevent apostrophes and quotes from appearing in permalinks?
- Removing hierarchical pages in the permalink
- Update URL Snippet to Canonical Permalink URL
- why does anchor name add a slash to url?
- “.#[random-char-string]” being inserted at end of URLs
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- WordPress on a subdirectory of Laravel – WordPress pretty permalinks inner page shows laravel
- Pretty Permalinks
- How to create a permalink structure for posts in a specific category
- How to get url of a post from admin panel
- How to get a page url by a page id?
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Remove subfolders from URL
- Why does WP not use relative links when linking pages?
- Menu Link Redirect Based on Username or User ID
- Social Media Links on homepage – within posts/post loop
- Limiting the number of words or characters in the slug/permalink
- flexible rewrite ‘ramble’ URLs with WordPress
- How to increase the character limit for post name of 200?
- How to get the post id from a permalink?
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- WordPress 3.4 Permalinks Redirection Problem
- Redirect user if it’s not logged in
- Make attachment pages require a base url
- How to Remove -14 from WordPress URL (Permalink)
- How to Modify Existing Rewrite Rules?
- Using ‘Primary Category’ in URL
- display URL or permalink instead of page title in dashboard
- custom permalink/shortlink with base62 encoded post ID
- How can I get the permalink of a post before it is published?
- Change permalink rule if category is called “uncategorized”
- Add a URL prefix to permalinks of News category and sub-categories of posts only
- Can two products with the same name but different category produce unique URLs?
- echo post-permalink without http and www
- I copied my site to another site but all links point to old site
- Get canonical link
- Best way to add internal link in widget
- Get closest page ID from URL
- How to reset canonical URLs / fix redirect loop
- CSS not loaded when omitting www. part of URL
- Setting up two separate blogs while using WordPress as a CMS
- How to show the homepage on a different url, like site.com/blog instead of site.com?
- Custom permalink for search and pagination
- wordpress api using rest_route for other pages
- Get page by path – honoring permalink settings (urls w/slashes)
- Automatically append ID to at the end of specific URLs
- Change blog segment of URL
- How to stop WordPress from removing & from URL?
- why some permalinks adding characters/ruining links
- Non latin post slug truncate
- Force wordpress to display page with same url structure as categories
- How to bulk edit image url in featured image and product description?
- Is there a link parameter that will show me all my published pages?
- How can i have a custom post type with more slugs for each post?
- How to change old permalink?
- URL rewriting: removing the site’s basename for a specific category
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- How to include sub directory in sitemap? [closed]
- How to eliminate permalink prefix in WordPress Multisite
- Remove -2 from URL; no duplicate pages, no images, no pages in trash
- WordPress keeps giving me the wrong permalink
- Host frontpage via example.com and everything else via example.com/blog
- WordPress can generate numeric permalinks, which then 404
- display dynamic content based on url slug on custom page
- Pre-populate Slug / Permalink with URL
- Relative v.s. absolute URLs: which ones should I use for cross-domain portability?
- How to use all tags in post permalinks
- Permalinks settings
- mod-rewrite exception? keep #hash in matching urls?
- Format HTTP links
- Unique one time use URL
- Can WP give a value a post ID?
- Remove parent page from url
- Suddenly new posts have the default permalink instead of the post name
- Problem with parent page slug only in WordPress admin
- Getting back a permalink from custom url
- Two URLs of one post is available
- “-2” Being added to end of URL (no duplicate pages, no pages in trash)
- Bulk append URL (add word to slug)