admin管理员组文章数量:1415096
I am using wp_editor in a custom meta box. It is saving the content to the post metadata. And displaying it in the meta box as it should.
The problem is when I am trying to display this content on the public-facing side of the website. It is displaying without the paragraphs. All other HTML that are part of the wp_editor content is displaying as they should.
My meta box code is as follows:
public static function as_bllp_create_call_to_action_meta_box( $post ){
/* Retrieve call to action content from post meta */
$as_bllp_call_to_action_para = get_post_meta( $post->ID, '_as_bllp_call_to_action_para', true );
//The call to action section is going to be an HTML editor
$settings = array(
'textarea_name' => 'as_bllp_call_to_action_para',
'textarea_rows' => 10,
'media_buttons' => false,
'wpautop' => false
);
echo '<div class="call-to-action-para">';
wp_editor(htmlspecialchars_decode( $as_bllp_call_to_action_para ), 'as_bllp_call_to_action_editor1', $settings);
echo '</div>';
}
Saving the wp_editor data with the following code:
/* Building args for allowed html for the content area filtering */
$allowed_html_tags = array(
'a' => array(
'href' => array(),
'title' => array(),
'rel' => array(),
'target' => array()
),
'br' => array(),
'p' => array(),
'em' => array(),
'strong' => array(),
'h1' => array(),
'h2' => array(),
'h3' => array(),
'h4' => array(),
'h5' => array(),
'ul' => array(),
'ol' => array(),
'li' => array()
);
if ( !empty( $_POST[ 'as_bllp_call_to_action_para' ] ) ){
/* Stripping received content of all HTML tags except for allowed tags */
$html_content = wp_kses( $_POST[ 'as_bllp_call_to_action_para' ], $allowed_html_tags );
/* Converting HTML to preserve their meaning */
$as_bllp_call_to_action_para = htmlspecialchars( $html_content );
/* Save the call to action content in post meta */
update_post_meta( $post_id, '_as_bllp_call_to_action_para', $as_bllp_call_to_action_para );
}
The above part works just fine. It saves and displays the content in the metabox as it should. With proper formatting.
But it doesn't add the paragraphs back when I display it on the custom post type single template on the front end of the site. Using this code:
/* Retrieve call to action content from post meta */
$as_bllp_call_to_action_para = get_post_meta( $post_id, '_as_bllp_call_to_action_para', true );
/* echo the content for display */
echo htmlspecialchars_decode( wp_kses( $as_bllp_call_to_action_para, $obj1->allowed_html_tags ) );
$obj1->allowed_html_tags is the same as above.
I thought 'wpautop' => false argument should tell WordPress that I want to preserve the paragraphs. As indicated here:
Any ideas what I need to do differently to get the paragraphs formatting the same as entered in the meta box?
本文标签: wp editorwpautop is not working when displaying content saved using wpeditor in a custom meta box
版权声明:本文标题:wp editor - wpautop is not working when displaying content saved using wp_editor in a custom meta box 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745165803a2645670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论