When a user is on a subdomain in a multi-site WordPress site, create a dynamic link stays within subdomain

StackOverflow https://stackoverflow.com/questions/22514710

Question

So I have a multi-site WordPress environment that uses the following code to direct to another product; however, when on an environment that is not the canonical (e.g. if CNAME is aa.site.com, then ab.site.com, ac.stie.com, and ad.site.com all use the same codebase), the link directs you to the correct product and page or post, but with the CNAME - where as I would like the subdomains to stay when navigating through products.

<a href="<?php echo get_permalink( $this->get_field('page_id.ID') ); ?>" class="button">Product 2</a>

So far argument's sake, lets say that we are on http://ab.site.com/product_1/, and wish to go to http://ab.site.com/product_2/. Currently, the way the site was originally set up (not my doing, I would have rewritten the get_permalink function in the links.template.php to prep for this; however, it is too late in the game to do that now. There are far too many other things that would break.

Basically I am looking for a URL/URI ... thing. Can anyone help?

This would be the best way to do it if starting from the beginning: https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/link-template.php#L0

Was it helpful?

Solution

Ok, I figured it out. The solution is as follows:

<a href="<?php 
$url_endpoint = get_permalink( $this->get_field('page_id.ID') );
$url_endpoint = parse_url( $url_endpoint );
$url_endpoint = $url_endpoint['path'];
echo $url_endpoint; ?>" class="button">Go to next product</a>

:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top