Pass a php string to a javascript variable

You can use the wp_localize_script to pass a variable to your javascript.

Here is an example:

wp_register_script('your_script_name', 'path/to/script.js');
$variables = array (
    'footer_caption' => $attr['footer_caption'],
);
wp_localize_script('your_script_name', 'js_object_name', $variables );
wp_enqueue_script('your_script_name');

Then you can acces to this variable by:

js_object_name.footer_caption