• Resolved karenbeth

    (@karenbeth)


    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 to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • You want the images for each product to go to a predetermined URL? Each one to be different?

    Thread Starter karenbeth

    (@karenbeth)

    Each to be different

    • This reply was modified 6 years, 2 months ago by karenbeth.

    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/

    Thread Starter karenbeth

    (@karenbeth)

    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 6 years, 2 months ago by karenbeth.
    Moderator bcworkz

    (@bcworkz)

    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

    (@karenbeth)

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘No-follow code problem’ is closed to new replies.