2

How can I add an anchor element in my content. Both the id tag and name attribute are removed from the a tag by the WYSIWYG editor.

For example:

<p><a name="my-anchor">My anchor with a name attribute</a></p>
<p><a id="my-anchor">My anchor with an id attribute</a></p>

is replaced by:

<p><a>My anchor with a name attribute</a></p>
<p><a>My anchor with an id attribute</a></p>
2

There is a purify and a Clean-up option on a WYSIWYG field.

Clean up HTML? – Whether Craft should run through some HTML cleanup routines when the field is saved, including removing all tags, empty tags, and most style attributes.

Purify HTML? – Whether the field should run submitted data through HTML Purifier before getting saved to the database, removing any potentially malicious code. Note that this is meant to be be used when accepting input in a Rich Text field from un-trusted sources.

Turning the purify off, let's you output HTML. That being said, I'm not sure of what you are trying to achieve but inserting raw HTML into a WYSYWIG field isn't really the way to go about things. Maybe if you share the bigger scope of the issue, we can look into a better approach of your problem.

source: https://craftcms.com/docs/rich-text-fields

2
  • I want to allow anchors to be added in the body text so it is possible to refer/link to other parts of the content. As far as I know the Redactor WYSIWYG html editor does not have a function to add anchors (understandable because it will seldom be used) so it has to be added as raw HTML. Like you pointed out, the Purify HTML option removes the 'id' and 'name' attribute. I would like to customize the HTML Purifier to allow these attributes but according to the post craftcms.stackexchange.com/questions/16366/… this is not possible. – vinniecent Jan 23 '17 at 12:36
  • Disabling the Purify HTML option fixes this issue for me. – vinniecent Jan 23 '17 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.