Check Multisite

Is there a way to set an if statement to check for which multisite instance the user is on? Something like:

<If blog=1>
<Else if blog=2 />
Other content
<Else />
Alt content

I’ve only worked on one multisite as a project manager so I’m not super familiar with all the config options that WP allows when setting up a multisite, but given that subsites seem to be their own post type on the network level with unique post IDs, I assume it would be technically possible to implement a feature in L&L that would allow someone to create a query or conditional logic based on that. That being said, I’ve also seen some conversations amongst the devs about possible security concerns that would arise if L&L allowed a non-super-admin on one site in the multisite to query data from another site. So while there are conversations happening about adding more multisite-specific features, it’s being approached with caution to ensure that it’s implemented securely.

The only multisite-specific settings I’ve come across are for the URL tag which allows you to get the URLs for the network site root/home/admin. Even if there are fairly limited native multisite features at the moment, I think you should be able to achieve what you’re trying to do by creating conditional logic based on the URL of the current page. Assuming the number of sites is relatively fixed, I would think that you should be able to use the Route tag (if your multisite uses different subfolders for each site) or the URL tag (if your multisite uses subdomains for each site) to set up some conditional logic based on the current URL. You could also maybe use the List tag to define the names of all the sites in your multisites and you could even store that list in a separate template (calling it in with the Template tag as needed) to give you a single area to keep that list updated in case you need to refer to that list in multiple different templates.

I hope those are useful suggestions!

I’m sure I’m doing something wrong here… what is the correct way to check a URL? This is what I have:

<If url site is value=>

It really depends on what you’re trying to achieve. check is probably the most versatile of the core conditions of the If tag, so it might look something like this:

<If check="{Url current}" includes value="my-subsite-name">

I’m not sure exactly how you’d do this if you wanted to compare the current URL to all the values in a list, but maybe you could define a list and then write a list loop like

<Loop list=subsites>
  <If check="{Field}" in value="{Url current}">
    Do something.

I haven’t tested that but I feel like that should get you going in the right direction.

This worked perfectly! It’s only 3 options, so I just used the first suggestion :slight_smile:

1 Like