I try to pass a javascript array to a shortcode, but it seems to be sanitized/escaped. For example this character "[" generate that "`{`". What is the function to retrieve original data ?

Here is a shortcode example :

[shortcode jsarray="[{start:"19:30",end:"21:00",color:'#d99694'},{start:"20:00",end: "21:30",color:'#d99694'},],"]
Some text

Here is my shortcode render function :

public function render_html($atts,$content)
    $atts = shortcode_atts(array('jsarray' =>''), $atts);


    ob_start(); ?>
        <div  data="<?php echo base64_encode($jsarray) ?>">
           <?php echo $content; ?>
    return ob_get_clean();

EDIT : Here is the result in shortcode_atts function :

`{`{``start``:``19:30``, ``end``:``21:00``, ``color``:``#d99694``}, {``start``:``19:30``, ``end``:``21:00``, ``color``:``#d99694``}`}`

1 Answer 1


You're going to have other problems than the brackets because shortcode_parse_atts will have already parsed your attributes, and the various single and double quotes will confuse the regular expression used to do that.

If you need the exact string, perhaps you could get it from a custom field. Alternatively, and better, you could specify a number of attributes for your shortcode (time1start, time1end, time1color, etc.) and rebuild your Javascript at the back end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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