Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BronsonQuick/3615651 to your computer and use it in GitHub Desktop.
Save BronsonQuick/3615651 to your computer and use it in GitHub Desktop.
Add custom tags to TinyMCE in WordPress
<?php
/*
* Our client needed some data sent in XML tags from Gravity Forms notifications to their system. These tags were being stripped by
* TinyMCE when the client would switch from HTML to Visual. This was my fix for it.
*
*/
function sennza_add_custom_tinymce_tags( $init ) {
// Command separated string of extended elements
$ext = 'name[*],phone[*],src[*],ip[*],notes[*],email[*]';
// Add to extended_valid_elements if it alreay exists
if ( isset( $init['extended_valid_elements'] ) ) {
$init['extended_valid_elements'] .= ',' . $ext;
} else {
$init['extended_valid_elements'] = $ext;
}
// Super important: return $init!
return $init;
}
add_filter('tiny_mce_before_init', 'sennza_add_custom_tinymce_tags');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment