X

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.

Code Snippet:

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’.

Code Snippet:

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.

Code Snippet:

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.

Code Snippet:

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'  #
}
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!