Title: embed php in javascript to switch out image
Last modified: August 21, 2016

---

# embed php in javascript to switch out image

 *  [aaron9999](https://wordpress.org/support/users/aaron9999/)
 * (@aaron9999)
 * [13 years ago](https://wordpress.org/support/topic/embed-php-in-javascript-to-switch-out-image/)
 * I am trying to embed a some php in my javascript to switch out images…
 *     ```
       $(document).ready(function() {
           $('.small-port-images a:nth-child(3)').click(function() {
       	$('.large-port-image img').attr('src', '<?php echo get_stylesheet_directory_uri() ?>/images/large-brigham.jpg');
       	});
       });
       ```
   
 * I am not sure if I am approaching this correctly. Any advice?

Viewing 1 replies (of 1 total)

 *  [weavesque](https://wordpress.org/support/users/weavesque/)
 * (@weavesque)
 * [13 years ago](https://wordpress.org/support/topic/embed-php-in-javascript-to-switch-out-image/#post-3790596)
 * Instead of “get_stylesheet_directory_uri”, maybe it should be “get_stylesheet_directory_ur**
   l**“? Other than that, it seems like you’re doing it right, depending on what
   you’re trying to accomplish. Just know that the function will be echoed into 
   that javascript line when the page is loaded, not when the javascript gets to
   that line.

Viewing 1 replies (of 1 total)

The topic ‘embed php in javascript to switch out image’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [weavesque](https://wordpress.org/support/users/weavesque/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/embed-php-in-javascript-to-switch-out-image/#post-3790596)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
