Conditional Tags extended

In the snippet Conditional Tags I show of some basic use of WordPress excellent conditional tags, that let’s you place if-statements to filter the content or display certain stuff to certain people.

Since the whole thing really is basic PHP, you can extend the use of it by adding just a few characters.

if( !is_admin() ) {<br />
  # If the user is not Admin'  #<br />
}<br />

The !-char before the if-statement(is_admin), says ‘if not’ instead of ‘if’.

if( is_home() && is_page('1') ) {<br />
  # If the user is at the home page and the home page is a page with the ID 1 #<br />
}<br />

If you add && between two(or more) statements both need to be true for the code to execute. You could also just type AND.

if( is_home() || is_page('1') ) {<br />
  # If the user is at the home page or a page with the ID 1 #<br />
}<br />

The ||-chars says that one of the statements need to be true for the code to be executed. The word OR works to.

if( is_home() || is_page('1') ) {<br />
  # If the user is at the home page or a page with the ID 1 #<br />
}<br />

To learn more about conditional tags, visit the excellent WordPress Documentation.

Code Snippet:

<?php
if( !is_admin() ) {
  # If the user is not Admin'  #
}
?>

Posted in Conditional