On a multisite environment, get the subdomain value as variable

I’m trying to setup a multisite where everytime a new site is added, a DNS record is also added in Cloudflare. So far, the code is working but I’m having troubles trying to parse the subdomain value onto a variable.

This is the code so far:

function create_cloudflare_dns_record() {  //$  current_site = ''.$  get_blog_details->siteurl.''; //$  current_site = ''.$  substr( $  current_site, -8).''; //$  current_site = ''.explode('.', $  current_site).'';   /* Cloudflare.com | APİv4 | Api Ayarları */ $  apikey     = '778***************************c37'; // Cloudflare Global API $  email      = 'al******@***********.com'; // Cloudflare Email Adress $  domain     = 'mer*****.com';  // zone_name // Cloudflare Domain Name $  zoneid     = 'ecc**********************1e1'; // zone_id // Cloudflare Domain Zone ID //$  current_site   = ''.$  get_sites->path.''; $  current_site = explode('.', $  _SERVER['HTTP_HOST']);   // $  _SERVER['HTTP_HOST']  // A-record oluşturur DNS sistemi için. $  ch = curl_init("https://api.cloudflare.com/client/v4/zones/".$  zoneid."/dns_records"); curl_setopt($  ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($  ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($  ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($  ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($  ch, CURLOPT_HTTPHEADER, array( 'X-Auth-Email: '.$  email.'', 'X-Auth-Key: '.$  apikey.'', 'Cache-Control: no-cache', // 'Content-Type: multipart/form-data; charset=utf-8', 'Content-Type:application/json', 'purge_everything: true'  ));  // -d curl parametresi. $  data = array(      'type' => 'CNAME',     'name' => ''.$  current_site.'',     'content' => 'mer***.com',     'zone_name' => ''.$  domain.'',     'zone_id' => ''.$  zoneid.'',     'proxied' => true,     'ttl' => '120' );  $  data_string = json_encode($  data);  curl_setopt($  ch, CURLOPT_POST, true); curl_setopt($  ch, CURLOPT_POSTFIELDS, $  data_string); //curl_setopt($  ch, CURLOPT_POSTFIELDS, http_build_query($  data_string));  $  sonuc = curl_exec($  ch);  /*     //print_r($  sonuc); */  curl_close($  ch);    }   add_action( 'wp_insert_site', 'create_cloudflare_dns_record' ); 

None of the three different attempts for $ current_site at the beggining of the function is giving any result.

If I manually replace the value for $ current_site, the code is working.

Any help is greatly appreciated.

How can multiple subdomain be redirected to only one specific subdomain?

How can i redirect multiple subdomain to one specific subdomain using cloudflare page rule.

Note: redirect without changing the url path (only sub domain change)

For example:






If any of the 3 examples url is type in brower, the should automatically redirect to newsub.site.com

How can this be done using cloudflare page rule? Please help

Receiving emails on a Google domains subdomain

I purchased a domain from Google Domains, say, mydomain.tld. I do not plan to have any hosting/content on this domain as of now. I’m not using any external services or providers, just Google Domains and GMail.

I added the alias hello to my email forwarding settings in Google Domains. Now, any emails sent to hello@mydomain.tld get forwarded to my own GMail address.

Instead, I would like to use a subdomain for my alias, such as hello@abc.mydomain.tld (note the extra abc subdomain).

How can I configure MX records or other DNS entries in Google Domains to enable this?

How to move wordpress to subdomain, keeping only .htaccess and/OR index.php in root domain?

I would like to move all files & folders of the root directory to the subdomain & keep the root directory empty with only the .htaccess file or index.php

I tried to search a lot but fail to get the solution. Only one I got it but that is also not completely working.


It is working perfectly if I will move to the subdirectory, which is also mentioned on wordpress.org but moving to the subdomain is missing.

On this site – Frontpage is working perfectly but the link to the other posts are not working well.

How to correctly point a subdomain to my local server?

I have been using No-IP.com’s free service and a subdomain they provided to access my local server, which is on my computer. I use EasyPHP devserver as my local server.

In order to not continue to rely on No-IP.com’s service, I added an A Record to my own domain name (xxxxxxx.dev) and pointed the newly created subdomain (xxx.xxxxxxx.dev) to my IP address. However, it is not working.

As the time of writing this question, I have tested accessing my local server with my IP address and the subdomain provided by No-IP.com, and both works. It’s just my own subdomain (xxx.xxxxxxx.dev) that isn’t working, and my browser’s error message says it can’t establish a connection to the server at xxx.xxxxxxx.dev.

What am I doing wrong?

Some culprits I’m suspecting are:

  • SSL issue. Browsers automatically change the connection to a .dev domain to a secured connection. But my browser’s error message does not seem to suggest a SSL issue.
  • Anti-virus software issue. Not sure how to check if it is related. But I don’t see my anti-virus showing any warning.

How can I track subdomain acquisitions?

My property has multiple subdomains and each subdomain has it’s own view. I have Tag Manager setup to use the same cookie for all the domains, but I have not yet added the subdomains to the referral exclusion list.

The reason being: I want to be able to track the subdomain "referral" traffic. I want to be able to look at a user’s journey across the subdomains in a single view. If I add the subdomains to the referral exclusion list, they’ll be lumped into the "direct / none" acquisition category without a way to differentiate them, correct?

Will I get duplicate data if I let GA record the subdomains as referral traffic, but I have the auto-cookie feature enabled in GTM? Has anyone found a workaround for this dilemma?

Any help/guidance/suggestions are more than welcome!

Add a word to the first // wp_get_attachment_url // as the subdomain name

We use this code to display the link …

$  mp3Link = wp_get_attachment_url($  mp3_file_id); <a class="w3-black" href="'.$  mp3Link.'" rel="nofollow" >mp3</a> 

It looks like this now :

I want it to be like this :

I mean, I just want to do this by editing the above code

Redirect to subdomain not working when specifying http scheme

I’ve recently uploaded a website on a domain. Using the domain registrar (NameCheap) I’ve also applied a 301 redirect rule so that going to "@" (for example example.com) will redirect to www.example.com.

However, I noticed that if I specify the http scheme like so – http://example.com I get redirected to https://example.com, and get an ERR_CONNECTION_REFUSED error.

What’s the reason for that and how can it be fixed? Am I doing some things wrong?

I’ll mention that at first the 301 rule did not work when I specified to go to https://www.example.com, and only after replacing the https with regular http did it work (although when visiting the site, I still see in the URL that it is in fact using https).