Adding rel=“nofollow” Attributes to Magento Links
In this guide, we will show you how to add rel="nofollow" attributes to specific links in your Magento store. This is particularly useful for internal links that may not provide much SEO value and for external links where you don’t want to pass link juice.
Understanding rel=“nofollow”
The rel attribute in HTML allows you to specify the relationship between the current document and the linked resource. When you use rel="nofollow", it tells search engines not to follow the hyperlink to the specified page, effectively ignoring the link for SEO purposes.
Adding nofollow to product links
Let’s start with your product page example:
Add to Compare
To add nofollow to this link, you’ll need to modify the template file. In your Magento installation, navigate to:
app/design/frontend/<your_package>/<your_theme>/template/catalog/product/compare/links.phtml
Find the line containing the “Add to Compare” link:
<a href="<?php echo $this->getUrl('catalog_product_compare/index/add') ?>/product/<?php echo $_product->getId() ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a>
Change it to:
<a href="<?php echo $this->getUrl('catalog_product_compare/index/add') ?>/product/<?php echo $_product->getId() ?>" rel="nofollow" class="link-compare"><?php echo $this->__('Add to Compare') ?></a>
Other Product Page Links
Follow the same process for other links on the product page, such as “Add to Wishlist”, “Email a Friend”, and reviews. You’ll need to modify the respective template files under catalog/product/view, catalog/product/view/addreview.phtml, etc.
Adding nofollow to checkout page links
Terms and Conditions
Navigate to:
app/design/frontend/<your_package>/<your_theme>/template/checkout/onepage/terms.phtml
Find the link to the terms:
<a href="<?php echo $this->getUrl('checkout_agreements/agreements/view', array('_secure' => true)) ?>"><?php echo $this->__('Terms and Conditions') ?></a>
Change it to:
<a href="<?php echo $this->getUrl('checkout_agreements/agreements/view', array('_secure' => true)) ?>" rel="nofollow"><?php echo $this->__('Terms and Conditions') ?></a>
Login Link
Navigate to:
app/design/frontend/<your_package>/<your_theme>/template/customer/form/login.phtml
Find the login link:
<a href="<?php echo $this->getUrl('customer/account/login') ?>" class="action"><?php echo $this->__('Login') ?></a>
Change it to:
<a href="<?php echo $this->getUrl('customer/account/login') ?>" rel="nofollow" class="action"><?php echo $this->__('Login') ?></a>
Conclusion
Adding rel="nofollow" attributes is a straightforward process in Magento. However, it’s important to use this technique judiciously and only on links that truly don’t provide SEO value.
Remember, too many nofollow links can send conflicting signals to search engines about the importance of your pages. Always consider the context and purpose of each link before applying nofollow.
If you found this guide helpful, consider exploring more Magento development tutorials and tips at LaravelCompany. We cover a wide range of topics to help you optimize your e-commerce site.
Happy coding!