1

I use a button shortcode for my WordPress (see below).

As you can see, I can choose a color, put the link, specify something for the target attribute.

I would like to add rel nofollow to this wordpress button link shortcode but I don't know how to do it.

add_shortcode('button', 'shortcode_button');
function shortcode_button($atts, $content = null) {
    $atts = shortcode_atts(
        array(
            'color' => 'black',
            'link' => '#',
            'target' => '',
        ), $atts);

        return '[raw]<span class="button ' . $atts['color'] . '"><a href="' . $atts['link'] . '" target="' . $atts['target'] . '">' .do_shortcode($content). '</a></span>[/raw]';
}

Thanks

user3197512
  • 33
  • 2
  • 6

2 Answers2

1

Just add rel="nofollow" in your a link.

add_shortcode('button', 'shortcode_button');
function shortcode_button($atts, $content = null) {
    $atts = shortcode_atts(
        array(
            'color' => 'black',
            'link' => '#',
            'target' => '',
        ), $atts);

        return '[raw]<span class="button ' . $atts['color'] . '"><a rel="nofollow" href="' . $atts['link'] . '" target="' . $atts['target'] . '">' .do_shortcode($content). '</a></span>[/raw]';
}
Rikesh
  • 26,156
  • 14
  • 79
  • 87
0

use the below code... you have to use the do_shortcode() inside your this function. the reason is you are using another short code inside this.

add_shortcode('button', 'shortcode_button');
function shortcode_button($atts, $content = null) {
    $atts = shortcode_atts(
        array(
            'color' => 'black',
            'link' => '#',
            'target' => '',
        ), $atts);

        return do_shortcode('[raw]<span class="button ' . $atts['color'] . '"><a href="' . $atts['link'] . '" target="' . $atts['target'] . '" rel="nofollow" >' .do_shortcode($content). '</a></span>[/raw]');
}
  • Thank you for your answer. I've not tried the code you gave me but I've searched a little bit about the do_shortcode(). Look like it can be bad for some people, I don't know in my case... – user3197512 Mar 20 '14 at 06:48