Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
3  
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
1  
Why can't you use bloginfo ? –  Chris Aug 8 '11 at 19:45
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.