Title: WP strips CSS attributes
Last modified: November 23, 2018

---

# WP strips CSS attributes

 *  [joncosby](https://wordpress.org/support/users/joncosby/)
 * (@joncosby)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/wp-strips-css-attributes/)
 * I’m trying to use styles to mask an email address with this code:
 * .myemail:present{
    content: attr(data-domain) “\0040” attr(data-user); unicode-
   bidi: bidi-override; direction: rtl; }
 * When the page is published, WP strips the domain and user attributes and I’m 
   left with an ampersand displayed on the page. Is this another security feature?
   I’m not using anything but plain css. What’s going on? Please don’t tell me I
   need another plugin. I already have a different one for each task.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwp-strips-css-attributes%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/wp-strips-css-attributes/#post-10909192)
 * If you’re trying to add that in a post (or page) body, then that’s the wrong 
   way to do it. The page editor is well-renowned for borking things like this.
 * The good news is that you don’t need another plugin. You can use the CSS editor
   in the Customizer to add that CSS ino for the site, and it will keep it as it’s
   meant to be without any changes.
 *  Thread Starter [joncosby](https://wordpress.org/support/users/joncosby/)
 * (@joncosby)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/wp-strips-css-attributes/#post-10909227)
 * Thanks, but I’m using the customizer. Unfortunately, when I try to use this on
   the page above, it gets stripped when published:
 * `<span class="myemail" data-domain="seablues.net" data-user="blog"></span>`
    
   is stripped to `<span class="myemail"></span>`
 * leaving only the “@”.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/wp-strips-css-attributes/#post-10911687)
 * Yes, WP strips tag attributes in content that are not whitelisted. There is probably
   a way to whitelist your attributes, but I recommend you implement the desired
   output by using the [Shortcode API](https://codex.wordpress.org/Shortcode_API).
   The filter that strips attributes runs before shortcodes are expanded. Shortcodes
   are the go to work around for things you need that the editor tries to bork, 
   so it’s a good thing to learn to use.
 *  [Christopher Spires](https://wordpress.org/support/users/boda1982/)
 * (@boda1982)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/wp-strips-css-attributes/#post-10915442)
 * You could add those specific data attributes (`data-domain` & `data-user`) to
   the allowed HTML using the `wp_kses_allowed_html` [filter](https://developer.wordpress.org/reference/hooks/wp_kses_allowed_html/).
   For your specific example:
 *     ```
       function my_allowed_html($allowed, $context) {
   
         $allowed['span']['data-domain'] = true;
         $allowed['span']['data-user'] = true;
   
         return $allowed;
   
       }
       add_filter('wp_kses_allowed_html', 'my_allowed_html', 10, 2);
       ```
   
    -  This reply was modified 7 years, 4 months ago by [Christopher Spires](https://wordpress.org/support/users/boda1982/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘WP strips CSS attributes’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 4 participants
 * Last reply from: [Christopher Spires](https://wordpress.org/support/users/boda1982/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/wp-strips-css-attributes/#post-10915442)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
