WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I think this will be what I need if I change it to apply to anchors.

Do you think this will work? Do you know of a better way to do it?

How and where do I add this snippet to my theme?

The theme I'm using has a tinyMCE folder in the functions directory.

share|improve this question

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

    $("#content a").addClass("link_color");
share|improve this answer

i don't think it possible or easy to change the "make link button" in the tinymce

but in wordpress you can pull your custom style in the editor and apply it to a link ;)

maybe using somthing like that in your theme function.php :

add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
// add the style list to tinymce
function my_mce_buttons_2( $buttons ) {
    array_unshift( $buttons, 'styleselect' );
    return $buttons;

add_filter( 'tiny_mce_before_init', 'my_mce_before_init' );
function my_mce_before_init( $settings ) {

    $style_formats = array(
            'title' => 'Custom Class for Links', // title that apear in the list
            'selector' => 'a', // limited to specific html tag
            'classes' => 'myClass' // the class to add

    $settings['style_formats'] = json_encode( $style_formats );

    return $settings;

don't forget to add the definition of .myClass in your editor-style.css check add_editor_style() function for how to load and use custom sytle in WP editor

i hope this help you

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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