How to process the textarea field with the standard WordPress function wpautop() when clicking the button?

Here's the form:

<textarea id="my_ta">Lorem ipsum!</textarea>
<button id="button_processing_ta">Обработать</button>

Here's the handler (to function.php):

  function my_action_javascript() { ?>
      document.getElementById( 'button_processing_ta' ).addEventListener( 'click', function() {
        let my_ta = document.getElementById( 'my_ta' );

        // ???
        wpautop( my_ta.value );
  <?php }

  add_action( 'admin_print_footer_scripts', 'my_action_javascript', 99 );

Sorry for my English...

  • you would need to make a request to the server in javascript – Tom J Nowell Apr 8 at 11:39

Take a look at AJAX in Plugins which uses admin-ajax.php. This is a way for you to interact with WordPress via a javascript request to WordPress.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.