As above. I want to change the WordPress Edtior TinyMCE behavior when I click the underline button I want the TinyMCE to wrap my selection with <u></u> tags. Now, I know that the u tag was deprecated in HTML 4~ but according to W3 it can be used in HTML5 again. Anyways! I need a <u> tag - not a <span>.

Is there a way to change the default underline button behavior without any shortcodes or editing core files? Something like a hook to change the editor behavior in functions.php would be nice :) Thanks!

  • Check this question and answers.
    – Max Yudin
    May 3, 2016 at 8:27
  • Unfortunately, this solutions doesn't work. Tried turning the inline function into standalone one but still nothing, wraps with span.
    – pbe
    May 3, 2016 at 8:52

1 Answer 1


After few days I got it to work. Gotta check those core files, now I know how. Anyways, here is the working code:

function my_tiny_mce_tweaks( $first_init ) {
  $first_init['formats'] = '{' .
      'alignleft: [' .
          '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
          '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
      '],' .
      'aligncenter: [' .
          '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
          '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
      '],' .
      'alignright: [' .
          '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
          '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
      '],' .
      'strikethrough: {inline: "del"},' .
      'underline: {inline: "u"}' .

  return $first_init;
add_filter('tiny_mce_before_init', 'my_tiny_mce_tweaks');

Just add it to functions.php and you good to go. It will be probably easier if you remove the dots . and join the string. Hope it helps!

  • +1 but I assume you could have just change the value of $first_init['underline'] instead of redoing all values. it might cause problems if there are more then one plugin hooking on that filter May 4, 2016 at 14:01
  • It probably won't work. With the code above I'm changing the array part and 'underline' is a part of the string in that array part. Would be better to just change the underline part but without ex. RegEx it's not possible.
    – pbe
    May 4, 2016 at 15:30
  • Oh you are right May 4, 2016 at 15:44
  • 1
    json_decode() to parse the JSON, edit the array, then json_encode() the result.
    – Ast Derek
    Feb 23, 2017 at 2:37
  • Great idea @AstDerek but I get NULL from decoding that string... Any ideas why? I think that because for ex. alignleft isn't wrapped with "alignleft" quotation marks. Might be wrong tho.
    – pbe
    Feb 25, 2017 at 12:00

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.