The Ultimate Body Tags

It can be really easy to style your content and site if you have the right body tags setup and know a little bit of CSS.

Here is the ultimate set of body tags that will let you easily style everything from the <body> down.

<body
	id="
		<?php
		$post_parent = get_post($post->post_parent);
		$parentSlug = $post_parent->post_name;
		if (is_category()) { echo "CategoryPage"; }
		elseif (is_search()) { echo "SearchResults"; }
		elseif (is_tag()) { echo "Tag"; }
		else { echo $parentSlug; }
		?>"
	class="
		<?php
		if (is_category()) { echo 'category'; }
		elseif (is_search()) { echo 'search'; }
		elseif (is_tag()) { echo "tag"; }
		elseif (is_home()) { echo "home"; }
		elseif (is_404()) { echo "page404"; }
		else { echo $post->post_name; }
		?>"
>

Something to note about the page404 class, you need to make sure that you don’t start a class with a number, so that’s why it starts with a letter instead.

Use this code, however, when you implement it on your site:

<body id="<?php $post_parent = get_post($post->post_parent); $parentSlug = $post_parent->post_name; if (is_category()) { echo "CategoryPage"; } elseif (is_search()) { echo "SearchResults"; } elseif (is_tag()) { echo "Tag"; } else { echo $parentSlug; } ?>" class="<?php if (is_category()) { echo 'category'; } elseif (is_search()) { echo 'search'; } elseif (is_tag()) { echo "tag"; } elseif (is_home()) { echo "home"; } elseif (is_404()) { echo "page404"; } else { echo $post->post_name; } ?>">

If you have any thoughts or suggestions, would love to hear them in the comments!

via mimoymima

Leave a Reply

Your email address will not be published. Required fields are marked *