Search code examples
phpwordpress

Reload wordpress page if button is clicked


I'm trying to refresh the WordPress page with a input="button".

echo '<input type="button" name="refresh" id="refresh" value="Refresh"/>';

I've tried with...

onClick="' . header("Refresh:0") . '"

This just makes the page reload without the button being clicked and with...

if ( isset( $_POST['refresh'] )) {
        header("Refresh:0");
}

Solution

  • To reload the current webpage using a button or other trigger. There are several ways to do that.

    <input type="button" value="Refresh" onClick="window.location.reload()">
    <input type="button" value="Refresh" onClick="history.go(0)">
    <input type="button" value="Refresh" onClick="window.location.href=window.location.href">