Setting Target for Button Shortcode

Chrisnz
39 Posts
Chrisnz posted this 20 May 2015

Is it possible to set the link target when using the button shortcode (ie target="_blank")?
Doesn't seem to work

Is it possible to set the link target when using the button shortcode (ie target="_blank")? Doesn't seem to work
Vote to pay developers attention to this features or issue.
3 Comments
Order By: Standard | Newest
Support Team
Support Team posted this 21 May 2015

Hello

Unfortunately Button Shortcode does not support target attribute.
But you can use custom html instead of the shortcode;

<a class="bd-button" href="http://...">Button</a>

and for bootstrap button:

<a class="btn btn-warning" href="http://...">Bootstrap Button</a>
<a class="btn btn-warning btn-lg" href="http://...">Large Bootstrap Button</a>

Thank you,
Olivia

Hello Unfortunately Button Shortcode does not support target attribute. But you can use custom html instead of the shortcode; <a class="bd-button" href="http://...">Button</a> and for bootstrap button: <a class="btn btn-warning" href="http://...">Bootstrap Button</a> <a class="btn btn-warning btn-lg" href="http://...">Large Bootstrap Button</a> Thank you, Olivia
Chrisnz
39 Posts
Chrisnz posted this 21 May 2015

OK, thanks

OK, thanks
Stagger Lee
1833 Posts
Stagger Lee posted this 21 May 2015

Olivia,

say to your developers to change just this in shortcodes.php:

  • Added just 'target' => 'self'
  • And target="_'.$target.'".

So it is nice and not forced upon users. Only used if someone use target="_blank" inside button shortcode.

// Button
    public static function button($atts, $content='') {
        extract(shortcode_atts(array(
            'link' => '/',
            'type' => 'default',
            'style' => '',
            'size' => '',
            'icon' => '',
            'target'  => 'self'
        ), $atts));


        $classNames = 'btn   btn-info';
        $linkContent = $content;
        $styles = array('default' => 'btn-default', 'primary' => 'btn-primary', 'success' => 'btn-success',
            'info' => 'btn-info', 'warning' => 'btn-warning', 'danger' => 'btn-danger', 'link' => 'btn-link');
        $sizes = array('large' => 'btn-lg', 'small' => 'btn-sm', 'xsmall' => 'btn-xs');


        if ($type === 'bootstrap') {
            $classNames = 'btn';
            array_key_exists(strtolower($style), $styles) ? $classNames .= ' ' . $styles[strtolower($style)] : '';
            array_key_exists(strtolower($size), $sizes) ? $classNames .= ' ' . $sizes[strtolower($size)] : '';
        }


        if ($icon !== '') {
            $linkContent = '<span class="' . esc_attr($icon) . '">&nbsp;</span>' . $linkContent;
        }


        return '<a class="' . $classNames . '" href="' . esc_attr($link) . '" target="_'.$target.'">' . $linkContent . '</a>';
    };

Olivia, say to your developers to change just this in shortcodes.php: - Added just **'target' => 'self'** - And **target="_'.$target.'"**. So it is nice and not forced upon users. Only used if someone use **target="_blank"** inside button shortcode. // Button public static function button($atts, $content='') { extract(shortcode_atts(array( 'link' => '/', 'type' => 'default', 'style' => '', 'size' => '', 'icon' => '', 'target' => 'self' ), $atts)); $classNames = 'btn btn-info'; $linkContent = $content; $styles = array('default' => 'btn-default', 'primary' => 'btn-primary', 'success' => 'btn-success', 'info' => 'btn-info', 'warning' => 'btn-warning', 'danger' => 'btn-danger', 'link' => 'btn-link'); $sizes = array('large' => 'btn-lg', 'small' => 'btn-sm', 'xsmall' => 'btn-xs'); if ($type === 'bootstrap') { $classNames = 'btn'; array_key_exists(strtolower($style), $styles) ? $classNames .= ' ' . $styles[strtolower($style)] : ''; array_key_exists(strtolower($size), $sizes) ? $classNames .= ' ' . $sizes[strtolower($size)] : ''; } if ($icon !== '') { $linkContent = '<span class="' . esc_attr($icon) . '">&nbsp;</span>' . $linkContent; } return '<a class="' . $classNames . '" href="' . esc_attr($link) . '" target="_'.$target.'">' . $linkContent . '</a>'; };
You must log in or register to leave comments