Created
February 22, 2012 14:34
-
-
Save pragmatic-web/1885364 to your computer and use it in GitHub Desktop.
WordPress function to add the TinyMCE WYSIWYG editor to any custom field of type 'Textarea'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// important: note the priority of 99, the js needs to be placed after tinymce loads | |
// important: note that this assumes you're using http://wordpress.org/extend/plugins/verve-meta-boxes/ | |
// to create the textarea - otherwise change your selector | |
function admin_add_wysiwyg_custom_field_textarea() | |
{ ?> | |
<script type="text/javascript">/* <![CDATA[ */ | |
jQuery(function($){ | |
var i=1; | |
$('.verve_meta_box_content textarea').each(function(e) | |
{ | |
var id = $(this).attr('id'); | |
if (!id) | |
{ | |
id = 'customEditor-' + i++; | |
$(this).attr('id',id); | |
} | |
tinyMCE.execCommand('mceAddControl', false, id); | |
}); | |
}); | |
/* ]]> */</script> | |
<?php } | |
add_action( 'admin_print_footer_scripts', 'admin_add_wysiwyg_custom_field_textarea', 99 ); |
This is my solution:
$('textarea[name^="meta"]').each(function(i, e) {
var id = !e.id ? 'customEditor-' + i : e.id;
tinymce.init({
selector: '#' + id,
setup: function (editor) {
editor.on('change', function ( e, i) {
tinymce.triggerSave();
});
}
});
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when i use wp_editor in my widget / plugin it shows rich text but save button shows already saved and cant click
below code i use
` $content = 'Hello World!';
$editor_id = $this->get_field_id('text');
anybody can help ?