Rich-Text/Redactor hyperlink classes I’m trying to implement different hyperlink styles within a rich-text field by adding formatting options via a Redactor config file.

"formattingAdd": [
  {
    "title": "Button",
    "tag": "a",
    "class": "button"
  }
]


This isn’t working as expected though. The above, for example, adds a &lt;span&gt; around or within the &lt;a&gt; tag, occasionally removing the &lt;a&gt; tag altogether.

Is there a way to add classes to hyperlinks within a rich-text field?

Note: This rich-text field is already within a containing Matrix field, so that’s not an option.
If you only want to style how the link looks visually, and need a work-around, you could use my Redactor Styles for Craft plugin. If you add an inline style to the plugins Styles JSON object like this:

[
  {
    "btnName":"Action button", 
    "className":"btn-action", 
    "spanClass":"btn-action"
  }
] 


Depending on which order the user creates the link and marks the text/link and select style, you now can get the following markup from your rich text field:

&lt;span class="btn-action"&gt;&lt;a href="http://loremipsum.net"&gt;A link&lt;/a&gt;&lt;/span&gt;
&lt;a href="http://loremipsum.net"&gt;&lt;span class="btn-action"&gt;A link&lt;/span&gt;&lt;/a&gt;


If this works for you or not depends on your design. Unless there are some styles on the  that can't be removed, you could style it so that it looks the same by using:

.btn-action &gt; a,
a &gt; .btn-action { ... }  


You could also instruct your users to always create the link, then select the style, or the other way around. But, it's of course a very fragile solution. 

Thinking of making a new plugin just for creating more advanced links, the built in one doesn't really cut it.