How To: Use WordPress Conditional Tags In Thesis

by Greg Rickaby on June 3, 2009

So you want to use WordPress Conditional Tags (or statements) in your Thesis customization. No sweat! Here is a basic example of how to make stuff show up ONLY where you want it; using Thesis OpenHook

conditional-tags-thesis

EXAMPLE CODE

<?php if (is_front_page()) { ?>
this is the homepage

<?php } else if (is_single()) { ?>
this is a post

<?php } else { ?>
this is a page
<?php } ?>

What does all that mean?

1. If I’m on the homepage, write “this is the homepage”

2. Or if I’m on a post, write “this is a post”

3. Unless I’m on a page then write, “this is a page”

It doesn’t get any simpler.

You can post the above code into any hook in Thesis OpenHook (just remember to tick “Execute PHP”)

wordpress-conditional-tag-1

and it will show

wordpress-conditional-tag-2

Let’s say you wanted Featured Content Gallery to show up on the homepage and pages only. The syntax would look like this:

<?php if (is_front_page()) { ?>
<?php global $post; include(WP_CONTENT_DIR . '/plugins/featured-content-gallery/gallery.php'); ?>

<?php } else if (is_single()) { ?>

<?php } else { ?>
<?php global $post; include(WP_CONTENT_DIR . '/plugins/featured-content-gallery/gallery.php'); ?>
<?php } ?>

Notice the blank space below is_single())  That says, “If this is a post, do nothing”.

For further reading (and kick-ass examples) see the Official list of WordPress Conditional Tags

Related posts:

  1. How To: Get Featured Content Gallery to work in Thesis
  2. How To: Add/Remove Thesis Elements using custom_functions.php
  3. How To: Create a Sub-Loop in Thesis
  4. How To: Create a Featured Content Slider
  5. How To: Add Breadcrumbs without a Plugin

{ 8 comments… read them below or add one }

Frank-Hair Extensions Chicago September 1, 2010 at 14:27

Question, what if I wanted to basically just have a text appear on the home page only..using Thesis Hooks? Is that possible? For example, say I wanted to say Welcome on the top of the home page, but not on other pages. Can I use Thesis Hooks to accomplish this? Thank you for this useful info by the way.

Reply

Shaw Girl May 9, 2010 at 19:10

Hello! Your tutorials have been a HUGE help for me thus far! I do, however, have one problem. I was able to get the Featured Content Gallery slider on my blog using the Thesis Open Hook code from your other post. However, the slider was showing up on all of my pages, when I only want it to show up on my home page. When I implemented your code above, it replaced ALL of my pages with the home page (i.e. my “About” page, “Blog Roll” page, “Recipes” page and “What’s In Season” page all were replaced with the front page). I definitely didn’t want this but do want the slider to stay only on my home page. Any suggestions? I’ve left my site with the slider on each page since I didn’t want all my pages to look like my home page. Thanks so much!

Reply

Shiela April 29, 2010 at 21:59

Hello ,

I am testing my Thesis copy in local host and trying to setup it up
i want to show Featured Content Gallery in home page and blog page but i am running into problems.
In someone told me to add this code to thesis

Use this conditional :

if (is_front_page() || is_home())

But not sure where to put it

Please advise

Thank you

Reply

Trisha April 7, 2010 at 20:38

Would you happen to know how to write this to change a css class on a specific page? Say, if you’re on the page called blog, switch div id=”header” to div id=”header-blog”? I need to change the header image on that page only. Any help would be greatly appreciated!

Reply

Greg Rickaby April 8, 2010 at 09:17

You would use conditional tags in custom_functions.php to call a new stylesheet. For example here is what I do:


// Build Conditional CSS
function single_back() {
if (is_page('966')){
?>
<link rel="stylesheet" href="<?php bloginfo('template_url');?>/custom/single.css" type="text/css" media="screen, projection" />
<?php } }
add_action('wp_head', 'single_back');

Reply

the english guy August 14, 2009 at 08:53

Few people use the is_front_page() – should be used more!

Reply

Mark Settle June 4, 2009 at 09:25

Greg, articles like this make me glad I follow you on Twitter! Thanks!

Reply

Chris Baskind June 3, 2009 at 22:58

Which rather neatly answers my question on another article about placing the Featured Content Gallery on the home page — and teaches me how to handle similar stuff in the future. Thanks!

Reply

Leave a Comment

{ 4 trackbacks }

Previous post:

Next post: