 i have already written a couple of articles about body ids set a body id using php and setting body ids in expression engine but in a recent project i was looking for a more dynamic way to do it in php and wordpress i dont think its necessary to discuss the benefits of body ids because i have already discussed them in the other posts so if you still arent using body ids classes go read the articles and start using them the plan this seems so straightforward that im not sure why i didnt start with this method so basically i look at the uri and if it is equal to then i give it a body id of home otherwise i grab the first folder and set that as the body id example lets say that the uri is about team leadership the body id would be about ok the seems easy lets get to the code the code here is our setbodyid function function setbodyid $path = $ server request uri if $path === $bodyid = home else $bodyid = substr $path 1 strpos $path 1 1 return $bodyid if you are using this in wordpress put this function in your theme function php file then you want to call the function and assign it to a variable $bodyid = setbodyid finally if the $bodyid variable is not empty add the id attribute on the body tag body php if empty $bodyid echo id= $bodyid conclusion its so simple yet powerful this could also easily be recoded in other programming languages what do you think any ideas for improvement 