How to change HTML class based on URL in Wordpress PHP?

Dear Sitepoint community, greetings.

I took this sample code from Armani website to create my own:

One of my clients has 2 different website but wants to to connect them together in order to have 2 brands with 1 global woocommerce cart!

The connection process is complete as well as the tabs design. But 1 issue remaining:

When you click on the other tab the color changes, but since Wordpress is network enabled, the code will be the same in both websites!

I just need a simple php code that allows me to change the html class based on the url the visitor is in.

Example:
Store 1: store1.com
Store 2: store2.com

If is in Store 1: Tab of Store 1 is black and tab 2 is white
If is in Store 2: Tab of Store 1 is white and tab 2 is black

Hi Sora

This is more of a CSS question than PHP.

Example: The Armani website shown uses a separate background color for each li tab.

background-color: #fff; // Tab 1
//and
background-color: #292a2e; // Tab 2

Simple process if you no how CSS works.
It might be a good idea to post this in the HTML-CSS Section

In short, you need to add the css background colors to each .class for the separate tabs.

Barry

Moved to HTML & CSS

Are you saying that you cannot simply swap the tab classes in each page’s html?

If not then your question will most certainly require JS or some serverside language. CSS on its own cannot do what you want.

e.g.

3 Likes

Thank you for this!
I’ll give it a try

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.