[resolved] how to use WordPress functions in js file? (4 posts)

  1. danixland
    Posted 4 years ago #

    Hello everybody,
    I am developing a theme, and inside a javascript file I need to access a few WordPress functions like bloginfo()..

    How am I supposed to do this thing?? I use wq_enqueue_script() inside <head> tags to include my js files, but how can I bring WordPress functions to js??

    Thanks a lot in advance...

  2. Mark / t31os
    Posted 4 years ago #

    Sounds like you need wp_localize_script, Otto explains it's usage well in his blog here.

  3. danixland
    Posted 4 years ago #

    Thanks for your reply Mark...

    I was doing this same thing but in a different way...

    now I just have to learn how to read the parameters I'm passing inside my script...

    thanks a lot again!!

  4. danixland
    Posted 4 years ago #

    ok, I can set this thread as solved ;)

    for future reference, after using Otto's method, explained in detail on Mark's post, I had to modify the js script this way:

    jQuery(document).ready(function($) {
      var foo = params.foo;

    doing so I was able to retrieve the foo variable set up in the array on my header.php...

    thanks a lot, I hope this turns to be useful for others too!!

Topic Closed

This topic has been closed to new replies.

About this Topic