Forums

WordPress functions inside javascript (2 posts)

  1. alex05
    Member
    Posted 1 year ago #

    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 ?

  2. Michael Fields
    Theme Wrangler
    Posted 1 year ago #

    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://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/

Topic Closed

This topic has been closed to new replies.

About this Topic