Conditional CSS with PHP

I used this snippet of code to set a different css class or id based on the page template.

<div id="
if (is_page_template('template-home.php')){ echo "content-home";}
/*elseif (is_page_template('template-diff-bg-demo2.php')){ echo "template-diff-bg-demo2";}*/
else{ echo "content";}

It could be modified to be conditional based on being the the home page as well.

Also note that is had to be put in the code/document as a single line for it to work…..don’t know why…….

<div id="<?php if (is_page_template('template-home.php')){ echo "content-home";} /*elseif (is_page_template('template-diff-bg-demo2.php')){ echo "template-diff-bg-demo2";}*/ else{ echo "content";} ?>">

This snippet is based on code taken from this article on the Fearless Flyer website:


There are no revisions for this post.

Tags: , , , ,

No comments yet.

Leave a Reply