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' =>"",
'attr'=>""
), $atts ) );
return "<" . $tag . " " . $attr . " >";
}
But I don’t think that it’s a right way…
Please look at the TinyMCE Advanced plugin.
http://wordpress.org/extend/plugins/tinymce-advanced/
You can configure it to leave certain tags alone.
it’s really useful.
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.
Maybe it’s Kses that remove it.
Try this