Title: Suggestion for all plugin developers using shortcodes
Last modified: August 19, 2016

---

# Suggestion for all plugin developers using shortcodes

 *  [EnglishMike](https://wordpress.org/support/users/stringfold/)
 * (@stringfold)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/suggestion-for-all-plugin-developers-using-shortcodes/)
 * I am the author of the WordPress plugin [AZIndex](http://wordpress.org/extend/plugins/azindex/)
   which uses shortcodes for displaying alphabetical indexes on pages and posts.
 * Of course, when writing the plugin’s documentation on my blog, I wanted to display
   an example of my shortcode. Boy wasn’t that a pain! When editing, if I stayed
   in HTML mode I could escape the [ and ] characters but as soon as I forgot and
   went back into Visual mode, indexes would start popping up all over the place
   in my posts since my plugin would keep finding valid shortcodes in my documentation!
 * So, I finally decided I had to fix this once and for all. And the answer is really
   quite easy, and I suggest that other plugin developers who use shortcodes do 
   something similar. Basically, all you have to do is add an “escape” parameter
   to your shortcode filter:
 *     ```
       add_shortcode('az-index', 'az_insert_index');
   
       function az_insert_index($params) {
           extract(shortcode_atts(array('id' => 0, <strong>'escape' => 'false'</strong>), $params));
           if (<strong>$escape != 'true'</strong>) {
               $content = az_get_index_content($id);
           } else {
               // We just want to display the shortcode itself, not a substitution.
               $content = '[az-index id="'.$id.'"]';
           }
           return $content;
       }
       ```
   
 * So with the above code, when I just want to display the shortcode itself on my
   blog and not an index then instead of:
 * `[az-index id="1"]`
 * which AZIndex will attempt to convert to an index, I can put:
 * `[az-index id="1" escape="true"]`
 * which will correctly display **[az-index id=”1″]** in my post instead of an index.
 * If you write any sort of documentation for your plugin that appears on your blog,
   adding an escape parameter to your shortcode could save you a fair amount of 
   aggravation!

Viewing 1 replies (of 1 total)

 *  Thread Starter [EnglishMike](https://wordpress.org/support/users/stringfold/)
 * (@stringfold)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/suggestion-for-all-plugin-developers-using-shortcodes/#post-803546)
 * Oops, this was my first post with source code in it. Didn’t realize there is 
   no HTML allowed! Here is the code again, without the errant HTML this time:
 *     ```
       add_shortcode('az-index', 'az_insert_index');
   
       function az_insert_index($params) {
           extract(shortcode_atts(array('id' => 0, 'escape' => 'false'), $params));
           if ($escape != 'true') {
               $content = az_get_index_content($id);
           } else {
               // We just want to display the shortcode itself, not a substitution.
               $content = '[az-index id="'.$id.'"]';
           }
           return $content;
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Suggestion for all plugin developers using shortcodes’ is closed to new
replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [tip](https://wordpress.org/support/topic-tag/tip/)

 * 1 reply
 * 1 participant
 * Last reply from: [EnglishMike](https://wordpress.org/support/users/stringfold/)
 * Last activity: [17 years, 10 months ago](https://wordpress.org/support/topic/suggestion-for-all-plugin-developers-using-shortcodes/#post-803546)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
