Home » Wordpress » WordPress wp_editor shortcode issue

WordPress wp_editor shortcode issue

Posted by: admin November 30, 2017 Leave a comment


I have created a front-end editor using wp_editor that functions as it should.

Upon testing I have noticed that it is stripping out any shortcodes that have been inserted in the content. I have looked into this issue and found that it’s the ‘ob_’ (output buffering) that is removing them. If I remove this output buffering then the shortcodes display fine, but it breaks the functionality I have created for the editor.

How would I keep the code I am using below, but amend it to make sure that all shortcodes are being displayed? Any help/ideas greatly appreciated, S.

if(!is_feed() && current_user_can( 'manage_network' ) ) :

function ps_add_post_editor($content) {
global $post;
$settings = array(
    'wpautop' => true,
    'media_buttons' => false
    $content .= '<div id="content-edit-area" style="display:none;"><form action="" id="page-content-editor-panel" method="post"><span id="ajax_my_post_edit_nonce" class="hidden">' . wp_create_nonce( 'ajax_my_post_edit_nonce' ) . '</span>' . ps_get_wp_editor($post->post_content, 'textarea-' . $post->ID , $settings) . '<input type="submit" id="feesavebtn" value="Save" /></form><a href="#" id="cancelbtn">Cancel</a></div><br><br><div id="loadingmessage"><img src="'.get_template_directory_uri().'/images/loading.gif" /> saving...</div>

    <style type="text/css">
        #textarea-'.$post->ID.'_ifr, #textarea-'.$post->ID.' { min-height:700px !important; }

    <script type="text/javascript">
    var pageid = '.$post->ID.'; 
    var content;
    var editor = tinyMCE.get(\'textarea-'.$post->ID.'\');
    if (editor) {
        content = editor.getContent();
    } else {
        content = jQuery(\'#textarea-'.$post->ID.'\').val();
    return false;        

return $content;

function ps_get_wp_editor($content,$textarea,$settings) {
wp_editor($content, $textarea, $settings);
$edior_html_code = ob_get_contents();
return $edior_html_code;
add_filter('the_content', 'ps_add_post_editor');

add_action('wp_ajax_add_foobar', 'prefix_ajax_add_foobar');
add_action('wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar');

function prefix_ajax_add_foobar() {
if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax_my_post_edit_nonce' ) )           {      
    $myfee_post = array();
    $myfee_post['ID'] = $_POST['post_id'];
    $myfee_post['post_content'] = $_POST['post_data'];
    wp_update_post( $myfee_post );      
    die("This page has now been updated."); 
} else {        
    die("Unable to process your request at this time.");


I have to admit, I’m not entirely sure what your goal is, but for what it’s worth this seems to work for me:

remove_filter('the_content', 'do_shortcode', 11);

function ps_get_wp_editor($content,$textarea,$settings = array()) {
   wp_editor($content, $textarea, $settings);
   $editor_html_code = ob_get_contents();
   return $editor_html_code;

function ps_add_post_editor($content) {
    global $post;

    $post_content = $post->post_content;
    $content = ps_get_wp_editor($post_content, 'ps-editor-' . $post->ID );
    return $content;
add_filter('the_content', 'ps_add_post_editor');

function ps_eat_pants() {
    return "eat pants has happened";
add_shortcode('eat_pants', 'ps_eat_pants');

The thing is, if you want to be able to EDIT The shortcode as it was in the editor on the back end, you need to remove the ‘do_shortcode’ filter from ‘the_content’ so that it doesn’t run when displayed on the front end.

I have to admit, I have no idea how the code you posted actually worked, I’m assuming that it was either mistyped or out of context. =)

I mean, there was no point at which you were actually giving your function all necessary parameters…

It might help if you explained what you were doing in greater detail, but I hope this helps.

[EDIT: Oh, and that “eat_pants” thing is just a test shortcode…]