Title: PHP if does not work
Last modified: August 19, 2016

---

# PHP if does not work

 *  Resolved [laviolette99](https://wordpress.org/support/users/laviolette99/)
 * (@laviolette99)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-does-not-work/)
 * I’m trying to implement a if statement to execute a script based on the author’s
   id and it does not work. The PHP engine says that there’s an unxepected < (the
   one that starts the script).
 * Here’s the code:
 * <?php
    $atr=get_the_author_ID(); if ($atr==6) { <script type=”text/javascript”
   > var gaJsHost = ((“https:” == document.location.protocol) ? “[https://ssl.&#8221](https://ssl.&#8221);:“
   [http://www.&#8221](http://www.&#8221);); document.write(unescape(“%3Cscript 
   src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/
   script%3E”)); </script> <script type=”text/javascript”> var pageTracker = _gat.
   _getTracker(“UA-697623-9”); pageTracker._initData(); pageTracker._trackPageview();
   </script>
 * }
 * elseif ($atr==4)
    { <script type=”text/javascript”> var gaJsHost = ((“https:”
   == document.location.protocol) ? “[https://ssl.&#8221](https://ssl.&#8221); :“
   [http://www.&#8221](http://www.&#8221);); document.write(unescape(“%3Cscript 
   src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/
   script%3E”)); </script> <script type=”text/javascript”> var pageTracker = _gat.
   _getTracker(“UA-697623-19”); pageTracker._initData(); pageTracker._trackPageview();
   </script>
 * }
    ?>
 * How can I insert a script in a if statement?
 * Thanks,

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

 *  [iridiax](https://wordpress.org/support/users/iridiax/)
 * (@iridiax)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-does-not-work/#post-1057284)
 * > How can I insert a script in a if statement?
 * Try this format:
 *     ```
       <?php $atr=get_the_author_ID(); ?>
   
       <?php if ($atr==6) { ?>
       <!-- code here -->
   
       <?php } elseif ($atr==4) { ?>
       <!-- code here -->
   
       <?php } else { ?>
       <!-- code here -->
   
       <?php } ?>
       ```
   
 *  [t31os](https://wordpress.org/support/users/t31os/)
 * (@t31os)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-does-not-work/#post-1057285)
 * That’s right, either switch out of PHP using `?>` and `<?php` or use echo/print,
   or whatever else…
 * You code is being parsed as PHP, when you’re wanting to output into HTML, so 
   you need to either switch out, as per the example above or use echo/print, etc…
 *  Thread Starter [laviolette99](https://wordpress.org/support/users/laviolette99/)
 * (@laviolette99)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-does-not-work/#post-1057316)
 * It works marvelously!
 * Thanks to both of you guys!

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

The topic ‘PHP if does not work’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [laviolette99](https://wordpress.org/support/users/laviolette99/)
 * Last activity: [17 years, 1 month ago](https://wordpress.org/support/topic/php-if-does-not-work/#post-1057316)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
