Title: If statement
Last modified: August 20, 2016

---

# If statement

 *  Resolved [jamieComerford](https://wordpress.org/support/users/jamiecomerford/)
 * (@jamiecomerford)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/if-statement-4/)
 * Hi there
 * i am relatively new to php and server side scripting. I am trying to include 
   an if/if else statement in of my pages on my wordpress website.
 * i am using the replacement shortcode ‘[insert_php]’ and ‘[/insert_php]’ instead
   of the php beginning header and footer.
 * What i would like to do is get the current users username and then just display
   some text if it is==’admin’. If the user name is==’volunteer’ display some other
   text.
 * What i have so far is:
 * [insert_php]
    $current_user=wp_get_current_user(); echo $current_user->user_login.‘‘;[/
   insert_php]
 * This just displays the username of the user logged in but how do i include an
   if/if else statement? I have tried multiple iterations such as below with no 
   success.
 * [insert_php]
    $current_user=wp_get_current_user(); [/insert_php] [insert_php]
   if($current_user==’admin’) : echo $current_user->user_login . ‘‘; endif; [/insert_php]
 * [http://wordpress.org/extend/plugins/insert-php/](http://wordpress.org/extend/plugins/insert-php/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [WillBontrager](https://wordpress.org/support/users/willbontrager/)
 * (@willbontrager)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/if-statement-4/#post-3291969)
 * The PHP code works with the plugin only when it isn’t broken up. In other words,
   it needs to be all one block of PHP code, complete in itself.
 * The reason is because the code between the [insert_php] and [/insert_php] markers
   are processed separately, unlike a regular PHP page where the entire page is 
   scanned and processed.
 * This works:
 *     ```
       [insert_php]
       if(true) {
       echo "other stuff";
       }
       [/insert_php]
       ```
   
 * But this, because each chunk isn’t complete in itself, will not work within the
   PHP plugin.
 *     ```
       [insert_php] if(true): [/insert_php]
       other stuff
       [insert_php] endif;[/insert_php]
       ```
   
 * And neither will this work.
 *     ```
       [insert_php]
       if(true){
       [/insert_php]
       other stuff
       [insert_php]
       }
       [/insert_php]
       ```
   
 * Insert PHP will successfully process only PHP code complete within itself between[
   insert_php] and [/insert_php] markers.
 * Will
 *  [WillBontrager](https://wordpress.org/support/users/willbontrager/)
 * (@willbontrager)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-statement-4/#post-3292027)
 * Gratuitous content so the system will accept the “resolved” checkbox.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘If statement’ is closed to new replies.

 * ![](https://ps.w.org/insert-php/assets/icon-256x256.gif?rev=3523853)
 * [Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts](https://wordpress.org/plugins/insert-php/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-php/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-php/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-php/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-php/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-php/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [WillBontrager](https://wordpress.org/support/users/willbontrager/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/if-statement-4/#post-3292027)
 * Status: resolved