Title: Call a PHP snippet inside JavaScript?
Last modified: August 21, 2016

---

# Call a PHP snippet inside JavaScript?

 *  [Ashutosh](https://wordpress.org/support/users/ashubetta/)
 * (@ashubetta)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/call-a-php-snippet-inside-javascript/)
 * Hello! I have this line of PHP that I want to insert in a sidebar widget, but
   only if certain conditions are met:
 *     ```
       <script>
          if (window.innerWidth > 1024) { //Somehow call PHP here }
       </script>
       ```
   
 * I created a shortcode for the PHP and tried putting it inside `document.write('');`
   but that didn’t work.
 *     ```
       <script>
          if (window.innerWidth > 1024)
               { document.write('[shortcode]'); } //doesn't work
       </script>
       ```
   
 * Please help. Thanks.

The topic ‘Call a PHP snippet inside JavaScript?’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [Ashutosh](https://wordpress.org/support/users/ashubetta/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/call-a-php-snippet-inside-javascript/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
