This may not solve the problem, but I hope it helps you.
-
In the
sky_post_excerpts()
function, I used this to display the TinyMCE/classic editor: (the$data
isget_post_meta($post->ID, 'skyscraper_post', true)
)<?php wp_editor( $data, 'post_meta_box', array('textarea_name'=>'skyscraper_post')); ?>
-
In the
post_meta_box_save()
function, I saved the meta like so, where$allowed
iswp_kses_allowed_html()
:update_post_meta( $post_id, 'skyscraper_post', wp_kses( $_POST['skyscraper_post'], $allowed ) );
-
On the front-end, I display the metadata like so:
// This is really just an example. And I was on a single post. echo get_post_meta( get_the_ID(), 'skyscraper_post', true );
And everything worked well for me — all HTML remained as generated by the TinyMCE editor.
UPDATE
if I use visual not text in TinyMCE then the p tags doesn’t show
wp_kses_allowed_html()
when called without specifying the $context
parameter, will use the global variable $allowedtags
which is an array of KSES allowed HTML elements, which (by default) do not include p
tags/elements.
If you want to allow p
elements, you can:
-
Use
wp_kses_allowed_html( 'post' )
which will use the global variable$allowedposttags
which also holds similar array as the$allowedtags
variable, but$allowedposttags
has many elements allowed includingtable
andvideo
. -
Or manually enable the
p
elements:$allowed = wp_kses_allowed_html(); $allowed['p'] = array(); // allows all attributes!
-
Same as above, but build your own allowed tags:
$allowed = array(); $allowed['p'] = array(); // allows all attributes!
But, you shouldn’t allow all attributes.. so:
$allowed['p'] = array(
'class' => true,
'id' => true,
...other attributes...
);