Well, I'm editing WP theme and creating network so I need to get url and modificate it for use in <a></a>
tags. I created function called urlbg(); and on normal domain (like www.xyz.com) it works but in subdomain it don't work. I called functions in <a></a>
tags like so:
<a href="'. urlbg( 'ark') . '" title="ARK: Survival Evolved"><img src="'. content_url() .'/themes/newsgamer/images/ark.png"></a>
Problem is, in normal domain (like www.xyz.com) when i use functions eg. urlbg( 'ASD' ); i get ASD.xyz.com and thats what i want, BUT in other way when i use the same code in subdomain (like foo.xyz.com) and when i called function in urlbg( 'ASD' ); <a></a>
tags, i get foo.xyz.com/ASD. (but need ASD.xyz.com ). Sorry for my bad English I hope you'll understand me and know whats my problem.
Code of function urlbg();
function urlbg($prefix){
$siteUrl = get_site_url();
$url = str_replace("http://", "https://", "". $prefix . ".", $siteUrl);
return $url;
}
This should do the trick:
function urlbg($prefix){
$siteUrl = get_site_url();
$url = 'https://'.$prefix.strstr($siteUrl, '.');
return $url;
}
Assuming you will always have this pattern http(s)://something_to_replace.something_to_keep.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.