Pass a php string to a javascript variable

I need to pass a php string that is stored in $attr['footer_caption'] inside a shortcode function to a js file where the highcharts are initialized.

$fields = array(

        array(
            'label' => esc_html( 'Footer label' ),
            'description' => esc_html( 'Choose the footer label' ),
            'attr' => 'footer_caption',
            'type' => 'text',
        ),


public static function shortcode_ui_chart( $attr, $content, $shortcode_tag ) {

    $attr = shortcode_atts( array(
        'chart' => null,
        'footer_caption' => null,
    ), $attr, $shortcode_tag );

I’ve been reading about localize script but couldnt get it to work. Is there a simple way to perfom this? I want the string from that php array in this variable:

    Highcharts.setOptions({
  chart: {
          type: 'column',
          events: {
              load: function () {
                var teste 'WANT TO PASS $attr['footer_caption'] HERE'
                var label = this.renderer.label(teste)

Read more here: Pass a php string to a javascript variable

Leave a Reply

Your email address will not be published. Required fields are marked *