WordPress Conditional Tags and Statements that can help along the way
When looking to display specific content on page wether it be an image/copy/etc you will need a specific WordPress If Statement. Below are a list of WordPress If Statements you may need along the way, as well other specifics.
- is_home() – home page
- is_front_page() – front page
- is_single() – posts/attachments
- is_tag() – tag archive page
- is_archive() – archive page
- is_search() – search results pages.
- is_author() – author archived page.
- is_404() – 404: Not Found error page. OH SNAP!
1- If a page / if a specific page
<?php if( is_page('ID GOES HERE') ):?>
//stuff you want to do
<?php endif; ?>
1- If specific pages
<?php if( is_page('ID GOES HERE') || is_page('ID GOES HERE') || is_page('ETC') || is_page('ETC') ):?>
//stuff you want to do
<?php endif;?>
3- if a specific page show this, if not show something else
<?php if( is_page('ID GOES HERE') ):?>
//stuff you want to show on this page
<?php else: ?>
//stuff you want to show on the rest of the pages
//if this is left empty the nothing will appear in this section on the other pages
<?php endif; ?>
4- if the home page and/or front-page do this, if not do this
<?php if( is_home() || is_front_page() ) : ?> //what you want on the home page <?php else : ?> //what you want on the all the other pages <?php endif; ?>
5- if a specific category
<?php if( is_category('ID GOES HERE') ):?>
//do this, show that
<?php endif; ?>
5- if a specific post page
<?php if( is_single('ID GOES HERE') ):?>
//do this, show that
<?php endif; ?>
6- if a specific category and single page
<?php if( is_category('ID GOES HERE') || is_page('ETC') ):?>
//do this, show that
<?php endif; ?>
7- Check if user is loggin in
<?php if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
} else {
echo 'Welcome, visitor!';
};
?>
8- Show Content if registration is opened and/or closed
<?php if ( get_option('users_can_register'):
echo 'Registration is opened.';
else;
echo 'Registration is closed.';
endif;
?>
9- Check if they are on a PC or MAC
<?php if( stristr($_SERVER['HTTP_USER_AGENT'],"mac") ):
echo 'MAC.';
else;
echo 'PC.';
endif;
?>
Hopefully the follow WordPress If Statements can help you along the way. Enjoy!