Add class to all links created by tinyMCE in WordPress

I’m attempting to automatically add a class to all links created when clicking the “link” button in tinyMCE. I’ve found this snippet in the tinyMCE docs:

// Adds a class to all paragraphs in the active editor
tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.dom.select('p'), 'myclass');
I think this will be what I need if I change it to apply to anchors.

Read More

Question 1: Think this will work? Know of a better way to do it?

Question 2: How and where do I add this snippet to my theme? The theme I’m working with has a tinyMCE folder in the functions directory.

Thanks!

Related posts

Leave a Reply

1 comment

  1. So I ended up doing a jQuery fix rather than going through tinyMCE. Code as follows:

    jQuery(document).ready(function(){
        $("#content a").addClass("link_color");
    });