Title: Adding schema support to TinyMCE (partial solution)
Last modified: August 31, 2016

---

# Adding schema support to TinyMCE (partial solution)

 *  [Chris](https://wordpress.org/support/users/comradeseidl/)
 * (@comradeseidl)
 * [10 years ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/)
 * So, like many other SEO-minded people who are hard-coding their schema into their
   posts, I’ve found that the TinyMCE editor automatically strips schema markup 
   when switching between Text and Visual post editor views, which is frankly incredible
   in 2016.
 * After some searching, I found [this partial solution](https://wordpress.org/support/topic/disable-wp-from-removing-unique-html-tags-for-schema?replies=3),
   which is apparently [taken from here](https://snipt.net/jamesw/prevent-tinymce-from-stripping-schemaorg-attributes-in-wordpress/).
   As one of the commentators on the latter page points out, there is a small error
   in the code, which is corrected as follows (with some code added):
 *     ```
       // Prevent TinyMCE from stripping out schema.org metadata
       function schema_TinyMCE_init( $in ) {
       	/**
       	 *   Edit extended_valid_elements as needed. For syntax, see
       	 *   http://www.tinymce.com/wiki.php/Configuration:valid_elements
       	 *
       	 *   NOTE: Adding an element to extended_valid_elements will cause TinyMCE to ignore
       	 *   default attributes for that element.
       	 *   Eg. a[title] would remove href unless included in new rule: a[title|href]
       	 */
       	if( ! empty( $in['extended_valid_elements'] ) ) {
       		$in['extended_valid_elements'] .= ',';
       	}
   
       	$in['extended_valid_elements'] .= '@[id|class|style|title|content|itemscope|itemtype|itemprop|datetime|rel],div,dl,ul,ol,dt,dd,h2,h3,h4,li,link,meta,span,a[rev|charset|href|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur]';
   
       	return $in;
       }
       add_filter('tiny_mce_before_init', 'schema_TinyMCE_init' );
       ```
   
 * Now, I should also mention that in my search, I found [this workaround to simply add a Custom Field](https://wordpress.org/support/topic/retain-microdata-code-toggling-between-views?replies=6)
   with the desired schema markup. However, this is not a proper solution for me,
   because it doesn’t allow you to enter the markup directly into the post body.
 * All schema elements seem to work for me so far, except for the <meta> element.
   I’m a bit dumbfounded why this element alone fails to work (with or without the
   optional closing “/”), so I was wondering if anyone could enlighten me as to 
   why this is, and hopefully even provide a solution.
 * Thanks for your time!

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

 *  [Tyler Shadick](https://wordpress.org/support/users/tyler-shadick/)
 * (@tyler-shadick)
 * [10 years ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/#post-7424626)
 * Hey Chris,
 * WordPress strips text for security purposes. The use case would probably be if
   you ran a WordPress.org site that had guest bloggers.
 * First off: Would this work? I didn’t do much research on it but it might do the
   trick.
    [https://wordpress.org/plugins/wp-seo-structured-data-schema/](https://wordpress.org/plugins/wp-seo-structured-data-schema/)
 * Another suggestion would be to use shortcodes to add schema markup. You could
   do this by making a quick plugin to add special forms of markup dynamically. 
   I did this for one of my plugin projects on GitHub, you could probably use that
   as a starting point
 * [https://github.com/TylerShadick/Vision2-Wordpress-Plugin/blob/master/V2_for_Wordpress.php](https://github.com/TylerShadick/Vision2-Wordpress-Plugin/blob/master/V2_for_Wordpress.php)
 * Hope this helps
    -Tyler
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/#post-7424649)
 * FWIW, the JSON-LD format inside of `<script>` tags do not get stripped from post
   content. The values are not visible to the user, which could be good or bad, 
   depending on what you’re trying to achieve.
 *  [ddickson01](https://wordpress.org/support/users/ddickson01/)
 * (@ddickson01)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/#post-7424851)
 * Hello bcworkz,
    I just ran into this problem and have seen that JSON-LD might
   work but am completely new at this so have no idea on how to add it to my individual
   pages. Do you have an example for one of my marked up pages? I only know how 
   to add the <itemprop=””> tags, then it gets stripped out when i edit the page.
   I was going to disable the visual editor but can not do that because people that
   write content for my site do not know how to use the html editor.
 * [http://www.omdetox.com/why-detox](http://www.omdetox.com/why-detox)
 * Thanks
 *  [ddickson01](https://wordpress.org/support/users/ddickson01/)
 * (@ddickson01)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/#post-7424852)
 * cheers
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/#post-7424853)
 * Hi ddickson01,
 * This example has nothing to do with your page, but shows the basic format. You
   can replace the schema data with whatever is appropriate.
 * When editing a page, switch to the text tab and insert the JSON-LD schema like
   so:
 *     ```
       <script type="application/ld+json">
       {
         "@context": "http://schema.org",
         "@type": "Person",
         "name": "John Doe",
         "jobTitle": "Graduate research assistant",
         "affiliation": "University of Dreams",
         "additionalName": "Johnny",
         "url": "http://www.example.com",
         "address": {
           "@type": "PostalAddress",
           "streetAddress": "1234 Peach Drive",
           "addressLocality": "Wonderland",
           "addressRegion": "Georgia"
         }
       }
       </script>
       ```
   
 * The important thing is the script tags, the schema can be anything appropriate.
 * When one swaps back to the visual tab, updates the page, then back again to text,
   the nice formatting will be destroyed, but the code remains valid. Because the
   schema is not visible in the visual tab, the schema can end up in a strange position
   within visually edited content, but it still remains valid.

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

The topic ‘Adding schema support to TinyMCE (partial solution)’ is closed to new
replies.

## Tags

 * [microdata](https://wordpress.org/support/topic-tag/microdata/)
 * [tinymce](https://wordpress.org/support/topic-tag/tinymce/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 4 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/adding-schema-support-to-tinymce-partial-solution/#post-7424853)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
