Exclude one regional site from hreflang

Dear all,
We are using C5 version 9.1 with PHP 7.3.33 and have implemented hreflang tag via /application/config/site.php. We want to exclude some regional website from the alternate url.

I’m using the following code:

<?php
return [
    'sites' => [
        'default' => [
            'multilingual' => [
                'set_alternate_hreflang' => true,
            ],
        ],
    ],
];

Can anyone help me to exclude some regional websites from alternate urls.

Thanks in advance.

In your application/bootstrap/app.php file you can add something like this:

app(Concrete\Core\Events\EventDispatcher::class)->addListener('on_header_required_ready', static function($event) {
    $tags = array_filter(
        $event->getArgument('alternateHreflangTags'),
        static function (string $tag): bool {
            return strpos($tag, 'https://exclude.me') === false;
        }
    );
    $event->setArgument('alternateHreflangTags', $tags);
});

of course, you have to customize the line

return strpos($tag, 'https://exclude.me') === false;
1 Like

Thank you Michele, it worked :slight_smile:

1 Like