Any ideas how I could add a cancel button, like the default one in the Publish meta box, to a custom meta box?

The standard code is <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel">Cancel</a> I guess it's using some js to do the cancel/reset action so it's not easy to replicate.

I basically want to add a button that will clear an input field in my meta box. input type=reset will clear all the fields on the page, so I wanted to see if I could use WP's toolset.

Open to ideas for the best solution here.

  • Have you added a cancel button? Even if it's non-functional, I think you can ignore the whole metabox/WP thing and treat this as a pure "I have a series on input form elements inside of a div container, how do I clear them when a link is clicked?". If you're looking for a WP specific way to do this though, there isn't one
    – Tom J Nowell
    Oct 20, 2018 at 17:31
  • Yeah, I was hoping for a Wordpress-specific way to do this. If there isn't something like that, then I can use a line of js to handle it.
    – Sal
    Oct 20, 2018 at 19:38

1 Answer 1


I ended up using this:

<a class="clear_button hide-if-no-js button-cancel" title="clear" data-clear style="text-decoration:underline;">Clear</a>

It does the job. I was hoping for something more "Wordpressy" but don't see a metabox cancel function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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