I am trying to trigger the echo when the form button will click. but not able to do this. if I don't use form and direct echo there. this is working. but when I use a form, it's not working.

can anyone help me with this?

add_action( 'add_meta_boxes', 'meta_box_cusotm_buttons' );
function meta_box_cusotm_buttons(){                                      // --- Parameters: ---
        'sync-with-server-metabox', // ID attribute of metabox
        'Server Action',       // Title of metabox visible to user
        'meta_box_callback', // Function that prints box in wp-admin
        'website',              // Show box for posts, pages, custom, etc.
        'side',            // Where on the page to show the box
        'high' // Priority of box in display order

function meta_box_callback( $post ){


        echo 'Hello';

    <form action="" method="post">
        <input name="connectToServer" type="submit" value="submit" />

  • What is a final purpose of this button? It's really bad practice to add several submit buttons on a form. Also, post edit page is a huge form already, and you are trying to add a form inside a form. (metabox holds form fields, not forms) – anton Jun 3 at 19:36
  • This is a custom post type where I have few fields. I need to create a button there on the left side near publish button (I have already created this as you can see on the code) to send the meta box data there with wp_remote_post. this function is working when I directly run the function there. but I want to create a button there. if the admin wishes to send data there then he can click the button to send the data. it's more like sync data. – Sarequl Basar Jun 3 at 19:50
  • 1
    You don't want to put a form in a form to do that, rather you'll want to bind that button to an AJAX process that executes your PHP for your wp_remote_post functionality. That way the button can be clicked without trigger the actual WordPress edit page form, and you can't since you can't echo again in PHP after it's been rendered, you'll also then be able to use AJAX to update whatever it is that needs updating. – Tony Djukic Jun 3 at 20:00
  • Thank you for the idea. now I am using ajax :) – Sarequl Basar Jun 17 at 20:30

Your Answer

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

Browse other questions tagged or ask your own question.