Adding "name" attribute to <a> tags in WYSIWYG editor... CKEditor or otherwise

801 views Asked by At

I have an application that builds emails, and part of the includes some non-standard things that you might not see in web such as adding a "name" attribute to links. I need a WYSIWYG and I'm 99% sure we are going with CKEditor so my question is:

1) Is there a way in CKEditor to add a "name" attribute to anchor tags? Is it possible/feasible to write a plugin?

2) If not CKEditor does any other WYSIWYG editors allow this

Here is what I need:

<a href="link.com" name="anchor_name">My Link</a>

Also it would be nice to be able to allow the end use to create custom tags for tracking purposes such as:

<a href="link.com" name="anchor_name" tracking="xs1234567">My Link</a>

Is this possible?

2

There are 2 answers

1
AlfonsoML On

By default CKEditor doesn't support that, but you can write your own plugin to extend the behavior.

The first thing to take into account is the "ACF" system that only allows a subset of elements, attributes, classes and styles, so you have to whitelist your attributes for the a elements.

Then you'll have to take the default link dialog and modify it, or create a plugin that modifies it on the fly to allow the user to set your attributes.

So it's just a matter of reading the documentation to learn how to create a plugin for CKEditor and start coding it.

0
Shubham Shinde On

Not Perfectly Relevant, but you can enable custom html tags like 'span' in WP and ACF editors:

function override_mce_options_and_add_tags($initArray)
{
    $opts = '*[*]';
    $initArray['valid_elements'] = $opts;
    $initArray['extended_valid_elements'] = $opts;
    return $initArray;
}
add_filter('tiny_mce_before_init', 'override_mce_options_and_add_tags');