Apply a class to a <h1> based on the site url
Posted
by
user1870639
on Stack Overflow
See other posts from Stack Overflow
or by user1870639
Published on 2012-12-02T17:01:17Z
Indexed on
2012/12/02
17:03 UTC
Read the original article
Hit count: 148
I'm new to PHP and want to apply a specific class to the title of my page depending on what part of the site the viewer is browsing.
For instance, I want to apply the class "blog" to the if the viewer is at domain.com/blog OR domain.com/blog/post-1 so on and so forth BUT apply the class "pics" if they're viewing domain.com/pics or domain.com/pics/gallery-1 etc etc.
I found something that could be modified to serve my needs using javascript here but I figured seeing as I'm using PHP already, it'd make more sense to keep this sort of thing server side.
As I say, I'm new to PHP. I've experimented with some regular expressions, but to no avail.
© Stack Overflow or respective owner