CKEditor + HTML Purifier - Setting Up Links for Administrators in Cotonti

A complete guide to changing link editor behavior. The administrator gets links with rel="dofollow" and without forced target="_blank", noreferrer, noopener. Regular users keep the default CKEditor behavior.

Rating based on reviews:
Total stars received: 0
Total reviews: 0
Average rating: 0
Filed under: User Blog

Setting Up rel="dofollow" Links for Administrators in Cotonti (CKEditor + HTML Purifier)

Description: A complete guide to changing link editor behavior. The administrator gets links with rel="dofollow" and without forced target="_blank", noreferrer, noopener. Regular users keep the default CKEditor behavior. All changes are made by editing the HTML Purifier preset and adding a conditional block in the template, without touching the system core.


Step 1. Configure HTML Purifier (allow rel="dofollow" and forbid target for the administrator)

File: plugins/htmlpurifier/presets/htmlpurifier.group_5.preset.php

Add the following two lines to the $htmlpurifier_preset array (if they are not already there):

'Attr.AllowedRel' => ['dofollow', 'nofollow', 'noreferrer', 'noopener', 'external', 'ugc', 'sponsored'],
'HTML.ForbiddenAttributes' => ['*@target'],

The first line tells HTML Purifier to keep the rel attribute on links with the listed values (including dofollow, which is stripped by default).
The second line completely removes the target attribute from all elements (including links), so the administrator will never get target="_blank".

Make sure that the same array contains 'HTML.Nofollow' => false (it is usually already there) — this disables the forced insertion of nofollow.


Step 2. Configure CKEditor (administrator only)

In the template that renders the editor (for example, market.edit.tpl, page.edit.tpl), insert the following block before the form:

<!-- IF {PHP.usr.maingrp} == 5 -->
<script>
var ckeditorConfig = {
    link: {
        addTargetToExternalLinks: false,
        decorators: {
            dofollow: {
                mode: 'manual',                // manual checkbox in the link dialog
                label: 'dofollow',             // label next to the checkbox
                attributes: {
                    rel: 'dofollow'            // the attribute to set
                }
            }
        }
    }
};
</script>
<!-- ENDIF -->

This code does the following:

  • Disables the automatic addition of target="_blank" and rel="noreferrer noopener" for the administrator.
  • Adds a checkbox labeled "dofollow" to the link insert/edit dialog.
    If the checkbox is checked — the link will get rel="dofollow".
    If it is unchecked — the link will remain without a rel attribute (or with whatever you type manually).

Regular users (not in group 5) will not see this block, and CKEditor will continue working for them with its default settings.


Step 3. Clear Browser Cache

After saving all files, open the page with the editor and press Ctrl+Shift+R (or Cmd+Shift+R on macOS) — this will load the updated scripts.


Result

  • Administrator:
    – Links never contain target="_blank", noreferrer, noopener.
    – A "dofollow" checkbox is available when inserting a link, controlling the rel attribute.
    – HTML Purifier no longer strips rel="dofollow" and removes target upon saving.
  • Regular user:
    – No change in behavior: external links still get target="_blank" and rel="noreferrer noopener".
  • Other templates: if CKEditor is used on other pages (articles, comments), repeat Step 2 for the corresponding templates.
  • Backward compatibility: if you need to temporarily revert to the old behavior for the administrator, simply remove or comment out the conditional block in the template. The Purifier settings can stay — they do not interfere.

This guide has been tested on Cotonti with CKEditor and HTML Purifier. If something goes wrong, make sure the files are saved without syntax errors and the browser cache is truly cleared.



Reviews

No reviews yet


Comments (0)

No comments yet
Only registered users can post new comments

Recommended Products and Services

Cotonti Services – Development, Support, SEO, Migration

Cotonti Services – Development, Support, SEO, Migration

Professional Cotonti services (Siena/Verona): plugin development, PHP 8.5 adaptation, themes,

Page Discussion in Telegram

Content author

webitproff

Offline

Sodium Carbonate

Last logged: 2026-08-04 15:17

  • Чем могу помочь?

    Оказываю весь спектр услуг по CMF Cotonti. Разработка открытых и закрытых корпоративных интернет порталов, небольших социальных сетей, торговые площадки, маркетплейсы, биржи фриланса, каталоги товаров оптовых поставщиков, интернет-магазин под заказ, чтобы делать совместные покупки и групповые совместные продажи от имени нескольких продавцов.

  • Разработки на GitHub бесплатно
    • Page published: 2026-07-29 18:45
    • Last update: 2026-07-29 19:30
    • Language: