Add no follow links in to buttonss?

Hey,

I only saw some old posts (3-4 years old) about this and needed to know if we can add "rel=‘nollow’ in the button tags now? Please don’t redirect me to some old post :slight_smile:

Thanks!

Hey @spinsr,

No Follow is an option in the Button element. If you’re using a Classic Button, you will need to replace it with the new Button element.

Thanks.

Hey Thank you for the reply!

I have my buttons inside a table with shortcodes can I add a nofollow in the shortcode?

Hello @spinsr,

Thanks for asking. :slight_smile:

You can follow solution mentioned in following thread to add rel attribute in button shortcode. https://theme.co/apex/forums/topic/how-to-add-nofollow-links-buttons-and-footer-menu/#post-177836

Thanks.

When clicking the link I get: “Oops! That page doesn’t exist or is private.”

Hi There,

Sorry for the inconvenience caused. It seems that the Button shortcode functionality also has been changed slightly and improved with X updates, so please follow the guide below with the latest code.

First of all, make sure that you have setup a child theme and make sure it is activated. Then add the following code into your child theme’s functions.php file.

function x_shortcode_button_nofollow( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'id'               => '',
    'class'            => '',
    'style'            => '',
    'type'             => '',
    'shape'            => '',
    'size'             => '',
    'float'            => '',
    'block'            => '',
    'circle'           => '',
    'icon_only'        => '',
    'href'             => '',
    'title'            => '',
    'target'           => '',
    'info'             => '',
    'info_place'       => '',
    'info_trigger'     => '',
    'info_content'     => '',
    'lightbox_thumb'   => '',
    'lightbox_video'   => '',
    'lightbox_caption' => '',
    'no_follow'         => ''
  ), $atts, 'x_button' ) );

  $id    = ( $id    != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class = ( $class != '' ) ? ' ' . esc_attr( $class ) : '';
  $style = ( $style != '' ) ? 'style="' . $style . '"' : '';
  $type  = ( $type  != '' ) ? ' x-btn-' . $type : '';
  $shape = ( $shape != '' ) ? ' x-btn-' . $shape : '';
  $size  = ( $size  != '' ) ? ' x-btn-' . $size : '';
  switch ( $float ) {
    case 'left' :
      $float = ' alignleft';
      break;
    case 'right' :
      $float = ' alignright';
      break;
    default :
      $float = '';
  }
  $block            = ( $block            == 'true'  ) ? ' x-btn-block' : '';
  $icon_only        = ( $icon_only        == 'true'  ) ? ' x-btn-icon-only' : '';
  $href             = ( $href             != ''      ) ? $href : '#';
  $title            = ( $title            != ''      ) ? 'title="' . $title . '"' : '';
  $target           = ( $target           == 'blank' ) ? 'target="_blank"' : '';
  $lightbox_thumb   = ( $lightbox_thumb   != ''      ) ? $lightbox_thumb : '';
  $lightbox_video   = ( $lightbox_video   == 'true'  ) ? ', width: 1080, height: 608' : '';
  $lightbox_caption = ( $lightbox_caption != ''      ) ? 'data-caption="' . $lightbox_caption . '"' : '';
  $no_follow         = ( $no_follow         == 'true'  ) ? 'rel="nofollow"' : '';

  $tooltip_attr = ( $info != '' ) ? cs_generate_data_attributes_extra( $info, $info_trigger, $info_place, '', $info_content ) : '';

  if ( is_numeric( $lightbox_thumb ) ) {
    $lightbox_thumb_info = wp_get_attachment_image_src( $lightbox_thumb, 'full' );
    $lightbox_thumb      = $lightbox_thumb_info[0];
  }

  if ( $lightbox_video != '' ) {
    $lightbox_options = "data-options=\"thumbnail: '" . $lightbox_thumb . "'{$lightbox_video}\"";
  } else {
    $lightbox_options = "data-options=\"thumbnail: '" . $lightbox_thumb . "'\"";
  }

  if ( $circle == 'true' ) {
    $output = "<div {$id} class=\"x-btn-circle-wrap{$class}{$size}{$block}{$float}\" {$style}><a class=\"x-btn{$type}{$shape}{$size}{$block}{$icon_only}\" href=\"{$href}\" {$no_follow} {$title} {$target} {$tooltip_attr} {$lightbox_caption} {$lightbox_options}>" . do_shortcode( $content ) . "</a></div>";
  } else {
    $output = "<a {$id} class=\"x-btn{$class}{$type}{$shape}{$size}{$block}{$float}{$icon_only}\" {$style} href=\"{$href}\" {$no_follow} {$title} {$target} {$tooltip_attr} {$lightbox_caption} {$lightbox_options}>" . do_shortcode( $content ) . "</a>";
  }

  return $output;
}

add_filter('init', function() {
   remove_shortcode( 'x_button' );

   add_shortcode( 'x_button', 'x_shortcode_button_nofollow' );
});

Then you can use the shortcode as follows.
[x_button shape="square" size="mini" no_follow="true"]Button Text[/x_button]

Hope that helps.
Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.