Title: No-follow code problem
Last modified: September 17, 2018

---

# No-follow code problem

 *  Resolved [karenbeth](https://wordpress.org/support/users/karenbeth/)
 * (@karenbeth)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/)
 * I have tried several things. I need to have the images open to an external website
   in a new tab (window). Also, I need to make sure all external links of affiliates
   will have nofollow so that my SEO is not affected.
 * Here is the code that works, however, it will not open in a new tab, and I don’t
   know how to put a no follow code in here.
 * Any help would be greatly appreciated!
 *     ```
       add_action('template_redirect', 'redirect_external_products');
       function redirect_external_products() {
           global $post;
           if (is_singular( 'product' ) &&
               ! empty( $post ) &&
               ($product = wc_get_product($post)) &&
                $product->is_type('external' )) {
   
               wp_redirect( $product->get_product_url() );
               exit;
           }
       }
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fneed-help-with-this-code-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [stefsternyc](https://wordpress.org/support/users/stefsternyc/)
 * (@stefsternyc)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10696807)
 * You want the images for each product to go to a predetermined URL? Each one to
   be different?
 *  Thread Starter [karenbeth](https://wordpress.org/support/users/karenbeth/)
 * (@karenbeth)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10696809)
 * Each to be different
    -  This reply was modified 7 years, 8 months ago by [karenbeth](https://wordpress.org/support/users/karenbeth/).
 *  [stefsternyc](https://wordpress.org/support/users/stefsternyc/)
 * (@stefsternyc)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10696850)
 * Have you looked at Affiliate plugins that may help with this?
 * Maybe this article can help?
    [https://bobwp.com/setting-up-external-products-and-affiliates-in-woocommerce/](https://bobwp.com/setting-up-external-products-and-affiliates-in-woocommerce/)
 *  Thread Starter [karenbeth](https://wordpress.org/support/users/karenbeth/)
 * (@karenbeth)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10696902)
 * Yes, I have read that. I have downloaded the plugin thirsty affiliate, and it
   states that it will make all links a no follow. However, if I put the code into
   my functions.php file I don’t think that thirsty affiliates will create the links
   as a no follow, because, I do have the box checked open all links in a new page
   and the no follow box checked. However, since I put the code into my functions
   PHP, it does not open in new page. So if that is not working, it is making me
   wonder if the no follow is not working.
 * I know that didn’t make any sense, but in woo commerce, the pictures do not open
   the affiliate link so I had to create the code and this is where my questions
   lie. since I did that, the thirsty affiliates plugin doesn’t seem to open the
   picture links in a new window.
 * I am new at this, so if I’m doing something totally crazy you can tell me. I 
   can handle it. LOL Thanks again for your help. And here is the code again that
   I put in the functions.PHP file.
    add_action(‘template_redirect’, ‘redirect_external_products’);
   function redirect_external_products() { global $post; if (is_singular( ‘product’)&&!
   empty( $post ) && ($product = wc_get_product($post)) && $product->is_type(‘external’)){
 *  wp_redirect( $product->get_product_url() );
    exit; } }
    -  This reply was modified 7 years, 8 months ago by [karenbeth](https://wordpress.org/support/users/karenbeth/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10697241)
 * You cannot nofollow an internal redirect like is done with wp_redirect(). All
   visitors are forwarded to the specified URL because a Location: header is sent
   in the response. Whether search bots honor and follow the Location: header, I
   cannot say. The nofollow attribute can only be used in HTML anchor tags, not 
   redirects. Same goes for opening in a new tab, a redirect is not the same as 
   following a link.
 * You could block access to the destination in the robots.txt file if the destination
   is on your site. If its external, all you can do is provide a link for visitors
   to click, which of course can then have nofollow and _blank attribute values.
 *  Thread Starter [karenbeth](https://wordpress.org/support/users/karenbeth/)
 * (@karenbeth)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10699594)
 * Thanks

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘No-follow code problem’ is closed to new replies.

## Tags

 * [no-follow](https://wordpress.org/support/topic-tag/no-follow/)
 * [open-new-tab](https://wordpress.org/support/topic-tag/open-new-tab/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 6 replies
 * 3 participants
 * Last reply from: [karenbeth](https://wordpress.org/support/users/karenbeth/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-this-code-2/#post-10699594)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
