Link to home
Create AccountLog in
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
}
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account