PHP code example of hryvinskyi / magento2-seo-robots-frontend

1. Go to this page and download the library: Download hryvinskyi/magento2-seo-robots-frontend library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hryvinskyi / magento2-seo-robots-frontend example snippets




namespace YourVendor\YourModule\Model;

use Hryvinskyi\SeoRobotsFrontend\Model\RobotsProviderInterface;
use Magento\Framework\App\HttpRequestInterface;

class CustomRobotsProvider implements RobotsProviderInterface
{
    /**
     * @inheritDoc
     */
    public function getRobots(HttpRequestInterface $request): ?string
    {
        // Your custom logic here
        // Return robots string like "NOINDEX,NOFOLLOW" or null if not applicable

        if ($someCondition) {
            return 'NOINDEX,NOFOLLOW';
        }

        return null;
    }

    /**
     * @inheritDoc
     */
    public function getSortOrder(): int
    {
        return 100; // Lower numbers execute first
    }
}