Title: WordPress functions inside javascript
Last modified: August 19, 2016

---

# WordPress functions inside javascript

 *  [alex05](https://wordpress.org/support/users/alex05/)
 * (@alex05)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-functions-inside-javascript/)
 * Hi, i’m currently developing a simple template for wordpress but i ran into a
   little problem.
 * Into the my template folder i have another folder called “lib” inside there is
   a file called jquery.ufvalidator.js, this file handles the form validation.
 * This is a part of the code
 *     ```
       $.formValidator.defaults = {
       		reqMailNotValid	:	'<img src="images/error.png" alt="img"/>',
       		reqMailEmpty	:	'<img src="images/error.png" alt="img"/>',
       ```
   
 * of course now the template can not recall the image in the images folder, how
   can i point the javascript to the right folder ? I tried to write `<?php bloginfo('
   template_url'); ?>/` but it did not work…
 * how can i fix this problem ?

Viewing 1 replies (of 1 total)

 *  [Michael Fields](https://wordpress.org/support/users/mfields/)
 * (@mfields)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-functions-inside-javascript/#post-1638938)
 * Something like this should work:
 *     ```
       wp_enqueue_script( 'mytheme-ufvalidator', '/full/path/to/jquery.ufvalidator.js', array( 'jquery' ) );
       wp_localize_script( 'mytheme-ufvalidator', 'myThemeUfvalidator', array( 'imagesUrl' => get_bloginfo( 'stylesheet_directory' ) . '/images/' ) );
       ```
   
 * Further reading:
 * [http://www.prelovac.com/vladimir/best-practice-for-adding-javascript-code-to-wordpress-plugin](http://www.prelovac.com/vladimir/best-practice-for-adding-javascript-code-to-wordpress-plugin)
 * [http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/](http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/)

Viewing 1 replies (of 1 total)

The topic ‘WordPress functions inside javascript’ is closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [Michael Fields](https://wordpress.org/support/users/mfields/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-functions-inside-javascript/#post-1638938)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
