Cross-Linking: help and documentation

Magento 2 Cross-Linking Developer Guide

Use the Magento 2 Cross-Linking API to add links to custom content. Apply admin rules, link limits and store scope to blogs, landing pages and blocks.

Cross-Linking
Version v1.1.0 Magento 2
Article updated on . Reading time about 1 minute.

Using the Cross-Linking extension from your own code. The extension links up product descriptions, category descriptions and CMS content on its own, but any other content — a blog post, a landing page, a block from a custom extension — can run through the same rules with one call. The rules, the limits and the store scoping a merchant configured in the admin all apply, so content from your own code behaves exactly like content the extension handles itself.

The service contract

Magmodules\CrossLinking\Api\CrossLink\ReplacerInterface is the entry point. Inject it like any other service:

use Magmodules\CrossLinking\Api\CrossLink\ReplacerInterface;

class MyBlogPostRenderer
{
    public function __construct(
        private readonly ReplacerInterface $crossLinks
    ) {
    }

    public function render(string $html): string
    {
        return $this->crossLinks->apply($html);
    }
}

That is the whole integration. The call returns the HTML with the active rules applied.

apply()

public function apply(
    string $html,
    ?int $storeId = null,
    ?int $maxLinks = null,
    ?string $currentUrl = null,
    ?string $contentType = null
): string;
Parameter What it does when you leave it out
$html Required. Empty content comes back untouched.
$storeId The store the visitor is on. Pass it when you render content for a store other than the current one, such as from a console command or a cron job.
$maxLinks The Default Max Links Per Page setting under General. Pass a number to use your own limit for this piece of content.
$currentUrl No self-link check. Pass the URL of the page you are rendering and a rule pointing at that same page is skipped, so the page does not link to itself.
$contentType The rule applies whatever kind of content this is. Pass one of ContentType::PRODUCT, CATEGORY, CMS or OTHER and a rule limited to certain content types knows whether it is wanted here.

The method respects the extension's own switches. With Cross-Linking disabled, or when no store can be resolved, the HTML comes back exactly as it went in — your code does not need to check anything first.

From a template

For a block that renders its own content, there is a ViewModel, so the template needs no PHP class of its own. Wire it up in layout XML:

<block name="my.content" template="My_Module::content.phtml">
    <arguments>
        <argument name="crossLinks" xsi:type="object">
            Magmodules\CrossLinking\ViewModel\CrossLinks
        </argument>
    </arguments>
</block>

And in the template:

<?php $crossLinks = $block->getData('crossLinks'); ?>
<?= /* @noEscape */ $crossLinks->apply($html) ?>

The output is HTML the extension built itself: attribute values on the links it inserts are escaped, and your own content is returned as you passed it in.

What the rules do to your content

The same guarantees apply as for the content the extension handles itself:

  • Text inside existing links is left alone. A keyword that already sits in an <a> tag is not linked a second time.
  • HTML attributes are left alone. A keyword in an alt or title attribute is not turned into a link.
  • Rules run in priority order, and at equal priority the longest keyword goes first, so "duffle bag" wins over "bag".
  • Limits are respected per keyword and per page. A rule with its own maximum stops there; the page as a whole stops at the limit you passed or the configured default.
  • Only rules for the store apply, including rules set to all store views.

Reading and writing rules

Rules themselves are available through Magmodules\CrossLinking\Api\CrossLink\RepositoryInterface, with the usual get(), save(), delete(), deleteById() and getList(). getActiveForStore() returns the active rules for one store in the order they are applied. The rule itself is a Magmodules\CrossLinking\Api\CrossLink\DataInterface with a getter and setter per field.

Use this when you want to create or maintain rules from your own code — an import, a sync with another system — rather than through the admin.

Upgrade safety

Everything under Magmodules\CrossLinking\Api is marked @api and follows semantic versioning: it will not change in a way that breaks your code within a major version. Classes outside Api are internal. Magmodules\CrossLinking\Service\CrossLink\Replacer in particular is the implementation behind the contract, not the contract itself — inject the interface, not the class.

Need More Help?

Documentation:

Support:

For a complete overview of features and configuration options, see Cross-Linking Extension for Automated Internal Linking.

Article Updated:
Download PDF
star star star star star
star star star star star
Gaaf - digital agency
We have tried the integration with SnelStart through several different providers, and this is the only solution that simply works. We needed support on two occasions, and it was provided quickly and professionally. We do recommend this company!
Google 12 May 2026
star star star star star
star star star star star
Andrew Velikiy
Great vendor with handy modules and quick support!
Google 13 Apr 2026
star star star star star
star star star star star
Alexandru-Manuel Carabus
Magmodules sets the bar for Magento module quality and support—we check their catalog first for client feature requests, and they’re our first choice for licenses.
Google 11 Nov 2025
star star star star star
star star star star star
Matt Austin
Possibly the fastest support response times of any Magento Extension vendor. Great extensions too!
Google 09 Sep 2025
star star star star star
star star star star star
Jan Privé
Dankzij de heldere uitleg en snelle reactie van Magmodules kon mijn vraag, en dus mijn Magento-probleem, binnen enkele uren worden beantwoord. Doeltreffend, zonder moeilijke termen, gewoon zo als het zou moeten zijn.... Bedankt!
Google 05 Sep 2025
star star star star star
star star star star star
Denis Metzler
To evaluate a provider, it is not enough to consider only the product offered, but also its after-sales service, such as support and troubleshooting. Magmodules has been extremely satisfactory at all levels on multiple occasions and sets the bar at the top when comparing the competition.
Google 02 Sep 2025
star star star star star
star star star star star
Bleijenberg winkelinrichting en materialen
Goed bereikbaar, reageren snel en denken oplossingsgericht. Een aanrader.
Google 30 Jul 2025
star star star star star
star star star star star
Patrick Verduijn
Magmodules biedt plugins aan die van hoge kwaliteit zijn tegen een goede prijs, waar dit bedrijf in uitblinkt is de bereidheid om de zeldzame feedback & problemen met de plugins te willen onderzoeken, mee te willen denken in het debuggen van problemen en goede oplossingen toe te passen. In mijn decennium ervaring met Magento & 3th parties is Magmodules absoluut een uniqum binnen de markt.
Google 25 Jul 2025
star star star star star
star star star star star
Erik de Groot
Magemodules heeft hele sterke Magento extensies en een proactieve support. Al jaren heel erg tevreden over jullie service en producten!
Google 18 Jul 2025
star star star star star
star star star star star
René Zeuner
We are using the Mollie Magento extension from Magmodules. It works excellently without flaws. Very fast, competent and friendly support. Thanks!
Google 30 Jun 2025