I try to insert a post with html tag with class attribute, like this: <dl class="dl-horizontal">, but after saving the post, WP removes an attribute.
How can I fix it?
The only way I've found, is to make a shortcode:

add_shortcode('attr', 'html_attr');
function html_attr( $atts, $content = null ){
 extract( shortcode_atts( array(
    'tag' =>"",
  ), $atts ) );   
  return "<" .  $tag . " " . $attr . " >";

But I don't think that it's a right way...

  • I can't duplicate this issue. The class attribute is not removed when I try it. Maybe you have a plugin conflict or your theme is doing something odd.
    – s_ha_dum
    Commented Dec 7, 2012 at 14:33
  • @s_ha_dum, I think that it deppends on wich tag we are talking about. I also see that in span and div tag I can insert class and WP does not remove it. But in dl tag WP removes attributes.
    – Shimon S
    Commented Dec 8, 2012 at 16:26
  • I thought about that and I tried it with the <dl> tag since that is the one you are using. It doesn't get stripped when I do it.
    – s_ha_dum
    Commented Dec 8, 2012 at 16:35

4 Answers 4


Please look at the TinyMCE Advanced plugin.


You can configure it to leave certain tags alone. it's really useful.

  • Unfortunately this plugin (now renamed "Advanced Editor Tools") no longer seems to do that.
    – clayRay
    Commented Jun 4, 2022 at 2:00

I had this problem when running multi-site and the user was only an admin of the site. I as super-admin could put whatever html attributes I wanted. I am sure the long term solution is not to raise their privileges, but it could be a place to start trouble shooting.

@jochem, I have gone down the route of making the tinymce changes, but that does not seem effect editing source.

If anyone has found a better solution, it would be helpful if it was posted.


Make sure you stay in the HTML mode in the text editor. Sometimes going back in and making changes in the Visual mode can overwrite HTML elements.

  • for sure I am in HTM mode
    – Shimon S
    Commented Dec 7, 2012 at 11:04

Maybe it's Kses that remove it.

Try this

function allow_dl_class_content() {
   global $allowedposttags, $allowedtags;
   $newattribute = "class";

   $allowedposttags["dl"][$newattribute] = true;
   $allowedtags["dl"][$newattribute] = true;
add_action( 'init', 'allow_dl_class_content' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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