Add this code in functions.php for Add wysiwyg editor in WordPress Meta Box:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php add_action('admin_init', 'wysiwyg_register_custom_meta_box'); function wysiwyg_register_custom_meta_box() { add_meta_box(WYSIWYG_META_BOX_ID, __('Custom WYSIWYG Meta Box', 'wysiwyg') , 'custom_wysiwyg', 'post'); } function custom_wysiwyg($post) { echo "<h3>Add Here Your Content:</h3>"; $content = get_post_meta($post->ID, 'custom_wysiwyg', true); wp_editor(htmlspecialchars_decode($content) , 'custom_wysiwyg', array( "media_buttons" => true )); } function custom_wysiwyg_save_postdata($post_id) { if (!empty($_POST['custom_wysiwyg'])) { $data = htmlspecialchars($_POST['custom_wysiwyg']); update_post_meta($post_id, 'custom_wysiwyg', $data); } } add_action('save_post', 'custom_wysiwyg_save_postdata'); ?> |
Hello!
Thanks for the cool script. But is there a way to add a second meta-box within this script and make it visible in my custom post types? I hope you can help me out with this…thanks in advance!
Only you need to Replace “post” with your custom post type Name for example
add_meta_box(WYSIWYG_META_BOX_ID, __('Custom WYSIWYG Meta Box', 'wysiwyg') , 'custom_wysiwyg', 'event');
in this code event is custom post type name.Hello,
Thanks a lot for the script! However how do you print it in the Front End of a template? I’m using the following code but the problem is that it displays the HTML (in the editor) as text:
$CustomWysiwyg = get_post_meta(get_the_ID(), ‘custom_wysiwyg’, true);
echo $CustomWysiwyg;
I really don’t find the way to print well… Thanks you!
Hi Mathieu,
Your Code is correct for call Editor Value, if you are add shortcode in your editor then you need to add do_shortcode() for print data like as:
$CustomWysiwyg = get_post_meta(get_the_ID(), ‘custom_wysiwyg’, true);
echo do_shortcode($CustomWysiwyg);
Thanks !
I use it like this.
wpautop – important part for correct text formatting.