Hey guys, I’ve added a TinyMCE to some textareas that are displayed in a custom meta box. All of the formatting works perfectly fine, except that the editor will not save <p>
or <br/>
tags. It doesn’t preserve the line breaks.
The TinyMCE is setup like this:
wp_tiny_mce(true, array('editor_selector' => $field['class'] ) );
'<textarea name="', $field['id'], '" class="', $field['class'], '" id="', $field['id'], '" cols="60" rows="8" style="width:97%">', $meta ? esc_html($meta) : $field['std'], '</textarea>';
And that all works perfectly fine. All the formatting buttons work fine, except for the <P>
and <BR>
tags.
I’m not sure if the editor is stripping them out before or after the post meta is saved.
Ideas?
I recently got this working. You should search and replace
metaname
with your meta box name.The key to maintaining formatting was using
wpautop();
when saving the data.This seems to have changed a little in subsequent versions of WordPress. You can now disable this functionality thusly:
Here’s (a pared-down version of) what I use to custom-configure TinyMCE:
I assume this is what you tried already?
EDIT:
You may need to include some other config changes, such as:
Play around with the TinyMCE configuration parameters, and find the one that you need to change.
Found perhaps a simpler workaround for this:
on the actual template, change this:
to this:
This way wpautop() adds the tags stripped out by TinyMCE on a template by template basis.
why not you use wordpress new function
wp_editor
to render the tinymce. That way everything will get handled. And when you show the content to the user apply the filterthe_content
.Like this:
The filter
the_content
will autmatically convert the link brakes to<br>
and<p>
.Another simple solution: Use Shortcodes!
Place this code into functions.php and use [br] in the content editor – HTML or visual – wherever you want a br tag to appear.
this is for who use the metaboxes for wordpress:
Plugin Name: Meta Box
Plugin URI: deluxeblogtips com/meta-box
i have modify the /vendor/meta-box/inc/fields/wysiwyg.php
in static function :
— BUT THE BETTER SOLUTION IS —
Put this into functions.php, it calls the filter from the metaboxes pluggin: