Are you looking for a way to use extended conditional tags in WordPress? While there’s probably a plugin for this, we have created a quick code snippet that you can use to use conditional tags in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
<?php if( !is_admin() ) { # If the user is not Admin' # } ?>
Since the whole thing really is basic PHP, you can extend the use of it by adding just a few characters.
if( !is_admin() ) { # If the user is not Admin' # }
The !-char before the if-statement(is_admin
), says ‘if not’ instead of ‘if’.
if( is_home() && is_page('1') ) { # If the user is at the home page and the home page is a page with the ID 1 # }
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') ) { # If the user is at the home page or a page with the ID 1 # }
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') ) { # If the user is at the home page or a page with the ID 1 # }
To learn more about conditional tags, visit the WordPress Documentation.
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress themes for affiliate marketing and how to use Google Optimize in WordPress.
Comments Leave a Reply