WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm guessing this is a really dumb question, but I'm far more familiar with PHP/WordPress and I'm just getting started with jQuery so I'm not even sure what to search on. Is there a way to pass the output of

echo get_blogifo('siteurl')

To jQuery? I'm trying to get this to work:

$('a.getstarted').attr('href', '<?php echo get_bloginfo('siteurl'); ?>/payroll-deduction-authorization/?plan=basic');

Thanks in advance for your help!

share|improve this question
You shouldn't use get_bloginfo or bloginfo, there's a great function called home_url() – kovshenin Aug 8 '11 at 19:10
Thanks! I've swapped it out. – Michelle Aug 8 '11 at 19:35
Why can't you use bloginfo ? – Chris Aug 8 '11 at 19:45
up vote 5 down vote accepted

Use wp_localize_script() to pass variables to the front end so that you can pick them by javascript.

Use it like this:

wp_enqueue_script( 'some_handle' );
$data = array( 'some_string' => __( 'Some string to translate' ) );
wp_localize_script( 'some_handle', 'object_name', $data );

And pick it up like object_name.some_string in javascript code.

share|improve this answer
Thank you!! Another really dumb question - how do I actually use that variable? I have the alert working so I know that part's good. I just have no clue how to add it to my line: $('a.getstarted').attr('href', my_home_object.my_home_url'/payroll-deduction-authorization/?plan=basic'); – Michelle Aug 8 '11 at 19:20
Nevermind - figured it out! I am feeling the jQuery love. :) $('a.getstarted').attr('href', my_home_object.my_home_url+'/payroll-deduction-authorization/?plan=basic'); – Michelle Aug 8 '11 at 19:27
this does not work on twenty theleve child theme. – sharif Nov 24 '14 at 14:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.