Title: Shortcode problem!
Last modified: May 10, 2023

---

# Shortcode problem!

 *  [tonygao](https://wordpress.org/support/users/tonygao/)
 * (@tonygao)
 * [3 years ago](https://wordpress.org/support/topic/shortcode-problem-42/)
 * 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 3 years ago by [tonygao](https://wordpress.org/support/users/tonygao/).
    -  This topic was modified 3 years ago by [tonygao](https://wordpress.org/support/users/tonygao/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Robert Anderson](https://wordpress.org/support/users/noisysocks/)
 * (@noisysocks)
 * [3 years ago](https://wordpress.org/support/topic/shortcode-problem-42/#post-16724873)
 * Hi [@tonygao](https://wordpress.org/support/users/tonygao/). Does it work if 
   you escape the `[` and `]` characters within the shortcode?
 *     ```wp-block-code
       [add_js]
       var a; 
       a&lsqb;0&rsqb; = ‘debug’; 
       alert(a&lsqb;0&rsqb;);
       [/add_js]
       ```
   
 *  Thread Starter [tonygao](https://wordpress.org/support/users/tonygao/)
 * (@tonygao)
 * [3 years ago](https://wordpress.org/support/topic/shortcode-problem-42/#post-16724907)
 * Tested! Not working!
 *  [Robert Anderson](https://wordpress.org/support/users/noisysocks/)
 * (@noisysocks)
 * [3 years ago](https://wordpress.org/support/topic/shortcode-problem-42/#post-16724919)
 * Does it work if we update the shortcode function to decode the HTML entities?
 *     ```wp-block-code
       function shortcode_add_js( $atts, $content ) {
           $decoded_content = htmlspecialchars_decode($content, ENT_QUOTES);
           return $decoded_content;
       }
       add_shortcode( 'add_js', 'shortcode_add_js' );
       ```
   
 *     ```wp-block-code
       [add_js]
       var a; 
       a&lsqb;0&rsqb; = ‘debug’; 
       alert(a&lsqb;0&rsqb;);
       [/add_js]
       ```
   
 *  Thread Starter [tonygao](https://wordpress.org/support/users/tonygao/)
 * (@tonygao)
 * [3 years ago](https://wordpress.org/support/topic/shortcode-problem-42/#post-16724949)
 * Not working too!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Shortcode problem!’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [tonygao](https://wordpress.org/support/users/tonygao/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/shortcode-problem-42/#post-16724949)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
