Avatar of Tintin
Tintin
 asked on

Check for string in WordPress Slug/URL

On my WordPress site, I have a structure like:

Home
page1
page2
Subject
   pageA
   pageB
      page2B
      page3B
About
Contact


where pageA, pageB, page2B and page3B all have "Subject" as their parent page.

I'm want to write a function that would detect if the term "Subject" is in the URL/page slug.

I've been trying various combinations of WordPress functions such as is_page() and get_ancestors(), but can't seem to find a way of achieving what I need.

So, the psuedo-code would be:


if (URL contains "Subject" or parent is "Subject") {
   echo something
}
else {
   echo something else
}
LinuxWordPressPHP

Avatar of undefined
Last Comment
Tintin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Tintin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23