• The following shortcode will not work!

    function shortcode_add_js( $atts, $content ) { return $content; } add_shortcode( ‘add_js’, ‘shortcode_add_js’ );

    [add_js]
    var a;
    a[0] = ‘debug’;
    alert(a[0]);
    [/add_js]

    The problem is char “[” and “]” are used by shortcode syntax!

    How to solve this problem?

    • This topic was modified 1 year, 6 months ago by tonygao.
    • This topic was modified 1 year, 6 months ago by tonygao.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @tonygao. Does it work if you escape the [ and ] characters within the shortcode?

    [add_js]
    var a; 
    a[0] = ‘debug’; 
    alert(a[0]);
    [/add_js]
    Thread Starter tonygao

    (@tonygao)

    Tested! Not working!

    Does it work if we update the shortcode function to decode the HTML entities?

    function shortcode_add_js( $atts, $content ) {
        $decoded_content = htmlspecialchars_decode($content, ENT_QUOTES);
        return $decoded_content;
    }
    add_shortcode( 'add_js', 'shortcode_add_js' );
    [add_js]
    var a; 
    a[0] = ‘debug’; 
    alert(a[0]);
    [/add_js]
    Thread Starter tonygao

    (@tonygao)

    Not working too!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Shortcode problem!’ is closed to new replies.