Magento 2

How to set a Meta robot values for Custom extension page in Magento 2

Beside of selling products online, the store owner still has to manage and take care of each and every aspect that helps to boost store sales and ranking over SERP pages. Securing your position in the top 5 ranking of Search engine pages drastically helps, but it requires a lot of efforts to build links, content, Meta’s, and everything that matters. Even the small start helps to achieve big, considering Magento comes with preloaded features of SEO options to set separate Meta values for each product, category pages, manage sitemap and much more that makes first pick CMS for the store owner. But what about custom extension pages?

Till today, we have developed more than 100+ custom Magento extensions to fulfill each client needs. Recently, while creating custom pages within an extension we came across the requirement of set-n-up custom Meta robot value for not indexing pages in search page results. You can do it too, either by using ‘layout.xml’ or using ‘Controller Layout Block’ by following the below steps.

1. Using Layout XML of the page :
In this method, you need to put below code into your Magento custom page layout file.
I.e. : app\code\Vendor\Extension\view\frontend\layout\vendor_extension_file.xml

<pre class="lang:default decode:true">
<head>
 <meta name="robots" content="NOINDEX,NOFOLLOW"/>
</head>
</pre>

2. Using Controller Layout Block:
For this method, you have to add following code inside your controller file from which all your Magento custom pages will be loaded.
I.e. : app\code\Vendor\Extension\Controller\Extension\Action.php

<pre class="lang:default decode:true">
<?php
namespace Vendor\ Extension\Controller\Extension;

class Action extends \Magento\Framework\App\Action\Action
{
    protected $_pageConfig;

   public function __construct(\Magento\Framework\View\Page\Config $pageConfig)
   {
      $this->_pageConfig = $pageConfig;
   }

   public function execute()
   {
      $this->_pageConfig->setRobots('INDEX,FOLLOW');
   }

}
</pre>

Also, you can play with these codes according to your need of setting up custom robot value for custom Magento extension pages.

Lastly, hit the below stars if this code works for you and comment down below if you face any issue while implementing this code inside your extension.

Happy Coding!

Click to rate this post!
[Total: 2 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

23 hours ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

23 hours ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

2 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

3 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

5 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

5 days ago