Your question seems to have been already answered by a user here:
https://stackoverflow.com/a/18516783/844732
However it sounds like your problem would be solved by using this plugin:
Relative URL
Relative URL applies wp_make_link_relative function to links to convert them to relative URLs.
Yoast also has some background on relative URLs.
Related Posts:
- How to use relative links on my pages?
- How can I store page ID in a post instead of other selected permalink?
- How to get a page url by a page id?
- Menu Link Redirect Based on Username or User ID
- Social Media Links on homepage – within posts/post loop
- Change website URL without breaking links or images? WP 3.3
- Redirect user if it’s not logged in
- I copied my site to another site but all links point to old site
- Best way to add internal link in widget
- Confusion about how a URL is being parsed
- Automatically append ID to at the end of specific URLs
- why some permalinks adding characters/ruining links
- How to change old permalink?
- Migrated from Windows to Linux. Any bulk methods for fixing case sensitivity?
- How to eliminate permalink prefix in WordPress Multisite
- Get the url of a page template without using the page slug and ID
- How to generate a list of all urls
- Format HTTP links
- Edit permalink for certain pages
- cannot link a external url, present page url acting as parent url
- Can WP give a value a post ID?
- Moved site, Old links in pages still pointing to old host
- How to use page jumps to top of banner and page title?
- How to remove the link of an image on WP 4.2
- Create custom links for excerpts with php dynamically
- How can I see a list of all pages my WordPress site has generated?
- How to make different urls for some tags pages
- A dash can replace a period in a link, how to fix it
- My WP homepage works, but the other pages don’t when accessing from out side of my network
- Can I link to content dynamically from a page to a new page?
- Propper way to set anchor and url param
- Find internal links to post
- rebuilding/ rewriting a url to make it SEO friendly
- Remove link function from oembed image or video
- How to change dynamic link to relevant post
- Difference and usage of uri (e.g. get_directory_uri) and absolute path (e.g. get_directory)
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- After changing permalink settings, everything works fine except for the two most recent posts
- Latin character conversion
- Pretty links for PHP pages above WP /blog directory?
- Permalink / sub-template issue
- Permalink structure as code in back-end?
- What is the issue with our links? It creates a loop
- wp_get_attachment_url not working
- Make all internal links relative, or otherwise make a website accessible from multiple domains
- How to get permalink and title from post ID?
- Using $_GET variables in the URL?
- Removing leading zeros from custom permalink structure
- Post being redirected to attachment post
- Without index.php in permalinks I get 404 across site
- Changing Permalinks to a Custom Permalink causes a 404 Error [no matter what I do]
- How to display comments on different page
- Category links suddenly started giving 404 errors
- Rewriting search permalink
- Dashes instead of slashes as permalink structure separator
- custom permalink/shortlink with base62 encoded post ID
- How to get permalink in foreach loop
- Disable permalinks on all pages and posts
- Custom add_rewrite_rule & permalinks
- Custom permalink for search and pagination
- WordPress permalinks that end with a hyphen result in a 404
- Confusing about permalink
- List / Get post redirects
- Programmatically Restrict WordPress from using certain URLs or sub-directories
- Title attributes on Permalinks for posts and products
- Permalinks problem – Category pages don’t work
- How to include sub directory in sitemap? [closed]
- 404 error using Meta for Permalink rewrite
- Environment independent way to link to certain pages on frontend
- Using one slug/post-name for multiple pages
- Custom URL rewrites for templates
- Gutenberg output URL to post from attribute with post ID
- How to change custom post type, blog post and page permalink by template?
- WordPress Permalink
- How to replace permalinks
- Multiple Tags Issue in Permalinks
- Adding a ‘blogs’ prefix in the URL structure but only for blogs
- .htaccess to redirect to a wp page
- How to redirect old permalinks to ones generated by [WP-Hashed-ID] plugin?
- Permalinks are not working in WordPress
- One post but two separate permalink structure and template views
- Retain Post title keywords in URL even if user changes post title or any other way to achieve SEO friendly permalink?
- HTTPS permalinks resulting in 404
- Changing Permalinks. Old links don’t work
- Automatically remove repeated words in slug
- Permalinks – Archives
- Dynamically populate permalinks
- Change Image depending on page path
- WordPress Permalinks 404 error
- ReWrite Permalink to New Permalink Nginx
- Permalinks of archive tag wordpress
- What is the best way to insert links indepently of the permalink structure?
- Appending a variable to RSS link url
- My wordpress site must be being affected by outside sources [duplicate]
- Hyperlinking images on posts to permalink
- Choose template depending on URL
- Create a permalink for a post’s attachments
- Permalinks not working after Migration – AllowOverride All, htaccess set
- Can I specify template to use with the_permalink?
- RSS feed URL for post comment shows HTML source code of page