Legacy Knowledge Base
Published Jul. 2, 2025

AlloyEditor or CKEditor will not allow html "a" tags to surround other heading tags

Written By

Alfonso Crisci

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

 AlloyEditor/CKEditor will not allow to use anchor (<a>) tags to surround other HTML elements like headings (<h1>, <h2>, etc...). For example, an HTML markup like this in the source tab: 

<a class="test" href="web">
  <h1><span>This is a test header <img alt="test" scr="https://test.com"
  /></span></h1>
</a>

 Will become 

<h1>
<a class="test" href="web"><span>This is a test header <img alt="test" scr="https://test.com" /> </span></a>
</h1>

after switching to the Rich Text Editor tab or publishing the content. 

Environment

  • Liferay DXP 7.0, 7.1, 7.2

Resolution

Override your editor's configuration so that such HTML structure is allowed.

For example, in a module that overrides the CKEditor, one line has to be added in the file: /src/main/resources/META-INF/resources/ckeditor/dtd_definition.js

CKEDITOR.dtd.a.h1 = 1;

The source code of a sample module is attached here for convenience

Additional Information

Note: CKEditor and Alloy Editor are provided as WYSIWYG Content Editors and are not intended to be HTML Editors. These editors' Source Modes are provided for convenience and are only intended for minor markup adjustments. Any markup entered into Source Mode is not guaranteed to remain unmodified nor intact.

Did this article resolve your issue ?

Legacy Knowledge Base