Question

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

Was it helpful?

Solution

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]';
}

OTHER TIPS

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]');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top