Search code examples
wordpressshortcodenofollow

Add a rel nofollow to shortcode in wordpress


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


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