Title: php if else &#8211; trying to execute javascript
Last modified: August 20, 2016

---

# php if else – trying to execute javascript

 *  Resolved [JaanMatti](https://wordpress.org/support/users/jaanmatti/)
 * (@jaanmatti)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/php-if-else-trying-to-execute-javascript/)
 * Hi,
 * I’m trying to execute a wordpress conditional tag according to instructions, 
   but I guess I’m doing something wrong. What I’m trying to do, is to display a
   jquery overlay on the whole page when a normal visitor visits the site. And not
   display the overlay, when I’m logged in.
 * The overlay works nicely, but I can’t get the if/else to work. Here’s the code:
 *     ```
       <?php
       		if ( ! is_admin() ) {
            echo '';
       } else {
            echo '<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.js"></script>
       		<script type="text/javascript" src="http://www.blanky.fi/wp-content/themes/TheFurnitureStore/overlay.js"></script>';
       }
       ?>
       ```
   
 * Basically what happens is, I can change the code either way, and it always only
   either displays the overlay in both cases (logged in and not), or never displays
   it (logged in or not). Can someone point out what I’m missing here?
 * Thanks,
    Jaan-Matti

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

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 8 months ago](https://wordpress.org/support/topic/php-if-else-trying-to-execute-javascript/#post-3014393)
 * Instead of `is_admin()`, have you tried `is_user_logged_in()`?
    [http://codex.wordpress.org/Function_Reference](http://codex.wordpress.org/Function_Reference)
   ↓ ↓
 *  [Chris Olbekson](https://wordpress.org/support/users/c3mdigital/)
 * (@c3mdigital)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/php-if-else-trying-to-execute-javascript/#post-3014395)
 * Your looking for the[ is_user_logged_in() ](http://codex.wordpress.org/Function_Reference/is_user_logged_in)
   conditional function.
 *     ```
       if ( ! is_user_logged_in() ) {
           //load your javascript
       }
       ```
   
 *  Thread Starter [JaanMatti](https://wordpress.org/support/users/jaanmatti/)
 * (@jaanmatti)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/php-if-else-trying-to-execute-javascript/#post-3014397)
 * Andrew, I just tried it, unfortunately that doesnt work either. It always just
   brings back one result – I either get the overlay in both cases, or none of the
   cases.
 *  Thread Starter [JaanMatti](https://wordpress.org/support/users/jaanmatti/)
 * (@jaanmatti)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/php-if-else-trying-to-execute-javascript/#post-3014400)
 * Thank You very much Chris, that idea worked as needed. Thanks to both of you.

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

The topic ‘php if else – trying to execute javascript’ is closed to new replies.

## Tags

 * [if else](https://wordpress.org/support/topic-tag/if-else/)
 * [ifelse](https://wordpress.org/support/topic-tag/ifelse/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [JaanMatti](https://wordpress.org/support/users/jaanmatti/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/php-if-else-trying-to-execute-javascript/#post-3014400)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
