Toggle button Save and load value without updating the page

How do I get the code below to be selected on all pages and send the selected value to the database. without refreshing the page.


            <button id="toggle" name="test" onclick="myFunction()">on</button>


                function myFunction() {
                    var change = document.getElementById("toggle");
                    if (change.innerHTML == "on")
                        change.innerHTML = "off";
                    else {
                        change.innerHTML = "on";


function update_your_meta_key( $post_id ) {
    if ( isset( $_POST['test'] ) ) {
        update_post_meta( $post_id, 'your_meta_key', $_POST['test'] );

And if it’s not too much to ask to update this plugin or file without reloading the page

You can also reload the page when clicked on the toggle button.

More would be better without reloading the page

Since I thank you:)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.