I'm adding a filed to a woocommerce shortcode button named 'onclick'. This is needed to track click events in Google Analytics.

This is how the code button short code looks after adding the onclick attribute:

```
function woo_shortcode_button( $atts, $content = null ) {
    extract( shortcode_atts( array( 'size' => '',
                                    'style' => '',
                                    'bg_color' => '',
                                    'color' => '',
                                    'border' => '',
                                    'text' => '',
                                    'class' => '',
                                    'link' => '#',
                                    'window' => '',
                                    'onclick' => '' ), $atts ) );

    // Set custom background and border color
    $color_output = '';
    if ( $color ) {
        $preset_colors = array( 'red', 'orange', 'green', 'aqua', 'teal', 'purple', 'pink', 'silver' );
        if ( in_array( $color, $preset_colors ) ) {
            $class .= ' ' . $color;
        } else {
            if ( $border ){
                $border_out = $border;
            } else {
                $border_out = $color;
            }

            $color_output = 'style="background:' . esc_attr( $color ) . ';border-color:' . esc_attr( $border_out ) . '"';

            // add custom class
            $class .= ' custom';
        }
    } else {
        if ( $border )
                $border_out = $border;
            else
                $border_out = $bg_color;

            $color_output = 'style="background:' . esc_attr( $bg_color ) . ';border-color:' . esc_attr( $border_out ) . '"';

            // add custom class
            $class .= ' custom';
    }

    $class_output = '';

    // Set text color
    if ( $text ) $class_output .= ' dark';
    // Set class
    if ( $class ) $class_output .= ' '.$class;
    // Set Size
    if ( $size ) $class_output .= ' '.$size;
    // Set window target
    if ( $window ) $window = 'target="_blank" ';
    // Set onclick
    if ( $onclick ) $onclick = 'onclick="'. $onclick .'" ';

    $output = '<a ' . $window . esc_attr($onclick) . 'href="' . esc_attr( esc_url( $link ) ) . '" class="woo-sc-button' . esc_attr( $class_output ) . '" ' . $color_output . '><span class="woo-' . esc_attr( $style ) . '">' . wp_kses_post( woo_remove_wpautop( $content ) ) . '</span></a>';
    return $output;
} // End woo_shortcode_button()

add_shortcode( 'button', 'woo_shortcode_button' );

```

Google Analytic's click event text looks like this:

```
_gaq.push(['_trackEvent', 'trackthis', 'Click', 'home-a']);

```

So a complete button short code example would be:

```
[button window="yes" onclick="_gaq.push(['_trackEvent', 'trackthis', 'Click', 'home-a']);"]hi[/button]

```

But when I publish it the code is broken and looks like:

```
<a target="_blank" onclick="&quot;”_gaq.push([‘_trackEvent’,&quot;" href="#" class="woo-sc-button  custom" style="background:;border-color:"><span class="woo-">);”]hi</span></a>

```

How do I properly output this text?

**UPDATE:**

When I try to implement the suggestions to remove the function using the below two changes:

```
if ( $onclick ) $onclick = 'onclick="'. esc_attr($onclick) .'" ';

$output = '<a ' . $window . $onclick . 'href="' . esc_attr( esc_url( $link ) ) . '" class="woo-sc-button' . esc_attr( $class_output ) . '" ' . $color_output . '><span class="woo-' . esc_attr( $style ) . '">' . wp_kses_post( woo_remove_wpautop( $content ) ) . '</span></a>';

```

I get:

```
<a target="_blank" href="#" class="woo-sc-button  custom" style="background:;border-color:"><span class="woo-">);"]hi</span></a>

```

**Update 2**:

Took suggestion to remove the encoding all together and add a space between the `$window` and `$onclick` variables:

```
if ( $onclick ) $onclick = 'onclick="'. $onclick .'" ';

$output = '<a ' . $window . ' ' . $onclick . 'href="' . esc_attr( esc_url( $link ) ) . '" class="woo-sc-button' . esc_attr( $class_output ) . '" ' . $color_output . '><span class="woo-' . esc_attr( $style ) . '">' . wp_kses_post( woo_remove_wpautop( $content ) ) . '</span></a>';

```

The output looks the same:

```
<a target="_blank" href="#" class="woo-sc-button  custom" style="background:;border-color:"><span class="woo-">);"]hi</span></a>

```

And just to clarify further, when the input doesn't include any special string the output is fine:

```
<a target="_blank" onclick="dosomething" href="#" class="woo-sc-button  custom" style="background:;border-color:"><span class="woo-">hi</span></a>

```