• Resolved Adetona

    (@adetona)


    Hi All,

    I’m currently building a plugin which requires me to remove the TinyMCE editor and replace with a text area.

    The following code helps me to remove the TinyMCE editor from the admin area:

    function wpdocs_remove_post_type_support() {
        remove_post_type_support( 'post', 'editor' );
    }
    
    add_action('init' ,'wpdocs_remove_post_type_support' );

    Then I add my own textarea with the following code:

    function myprefix_edit_form_advanced() {
    	
    
    require('texteditor.html'); 
    
    } 	
    
    add_action( 'edit_form_after_title', 'myprefix_edit_form_advanced' );

    My texteditor.html looks like this:

    <html>
    
    <head>
    
    </head>
    
    <body> 
    
    <div> 
     <textarea id="text" name="post_content" data-placeholder="start writing...">
     
     
     </textarea>
      
      </div> 
     </body> 
    </html>

    After all the above code, I was able to save content using the textarea but when I got to the edit post area, no post content is showing up in the textarea field. My question is, is there any function I can call to make sure the text field is filled up in the edit post area.

    I’d really appreciate any help.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Why are you requiring the field as an html file, and not just echoing it into the page? This means that you can’t run php inside it to get the current content.

    It’s also not valid HTML, because you’ve created an entire valid HTML document that you’re trying to insert into an existing document. You only need the text area element.

    This is what you need to do:..

    function myprefix_edit_form_advanced() {
    	global $post;
    	
    	echo '<textarea id="text" name="post_content" data-placeholder="start writing...">';
    	echo esc_textarea( $post->post_content );
    	echo '</textarea>';
    }
    add_action( 'edit_form_after_title', 'myprefix_edit_form_advanced' );
    
    Thread Starter Adetona

    (@adetona)

    I want to add some Javascript script to the top of the textarea. How do I do this?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you add it by enqueing the script like a normal script; why does it need to be in the DOM above the textarea?

    Thread Starter Adetona

    (@adetona)

    @anevins Please, can you point me to a guide on how to enque JS script in wordpress?

    Thread Starter Adetona

    (@adetona)

    Thank you guys. I’ve solved the problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post content not showing in the edit post textarea.’ is closed to new replies.