How to Add Link on Store Configuration Fields Comment in Magento 2
Whenever you are developing some extensions you need to add a few configurations with comments for user better understanding. However, in some cases, you want to add some comments with custom links to redirect the admin to another link for the best user experience. So, in this article, we are going to show you how to add custom links to backend configuration fields comment.
Before we start I assume, you have already a created custom module. If you don't have it or don't know how to create it then check out our other article How To Create a Magento 2 Module.
Let's get started !!
We hope you already have a system.xml file in your module. If you don't have it then check the below steps and create it.
Step 1: Create system.xml at app/code/Vendor/CustomValidation/etc/adminhtml and paste the below code. You need to change code as per your requirement.
saveCopyzoom_out_map<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
...
<field id="text" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Custom Text Field</label>
<comment>
<model>Vendor\CustomValidation\Model\Config\Comment</model>
</comment>
</field>
...
</system>
</config>
In the above code, you see we've used Vendor\CustomValidation\Model\Config\Comment to get a dynamic comment in the backend configuration. You'll use your model according to your requirement.
Now, let's create a model file to get a custom comment with links.
Step 2: Create Comment.php file at app/code/Vendor/CustomValidation/Model/Config/ to create module file. And paste the below code.
saveCopyzoom_out_map<?php
namespace Vendor\CustomValidation\Model\Config;
use Magento\Framework\UrlInterface;
class Comment implements \Magento\Config\Model\Config\CommentInterface
{
protected $urlInterface;
public function __construct(
UrlInterface $urlInterface
) {
$this->urlInterface = $urlInterface;
}
public function getCommentText($elementValue)
{
$url = $this->urlInterface->getUrl('*/*/*/section/configdemo');
return 'This is custom <a href="' . $url . '"target="_blank">Link</a>.';
}
}
Now, open Command line in folder root of magento and run the below commands.
saveCopyzoom_out_mapphp bin/magento c:c
You will see link in comment like the below screenshot.

That’s it,
We hope this Magento post helped you to know How to Add Link on Store Configuration Fields Comment in Magento 2. Bookmark it for your future reference. Do comment below if you have any other questions or doubts.
P.S. Do share this post with your team.
AI-Powered Recommended Articles
How to Add Dynamic Row on Store Configuration in Magento 2
Learn how to add dynamic rows to store configuration settings in Magento 2 for flexible content management.
Magento 2 - How to Add a Custom Link in Admin Order Listing Grid Page
Learn how to add a custom link to the admin order listing page in Magento 2 for enhanced order management.
Magento 2 - How to Add a Custom Link in Admin Product Listing Grid Page
Step-by-step guide to adding a custom link to the admin product listing page in Magento 2.
Magento 2 Add Custom Tab On Customer Account Section
Enhance the customer account section in Magento with custom tabs for better user experience.
How to Add Custom Admin Menu In Magento 2
Learn how to add a custom admin menu in Magento 2 for creating personalized admin sections.
How to Add Custom Select/MultiSelect Options on Store Configuration in Magento 2
Learn how to add custom select and multiselect options to the store configuration in Magento 2.