When I select a template for a page from the "Templates" selectbox, the selected item gets “value=selected” only after I hit save draft/publish/update.

<option value='template-gallery.php' selected='selected'>Gallery</option>

How can the option receive the value “selected” without the need of save/publish/update hit button? (like on widgets page: they get saved without page refresh)

Thank you!

  • because on widgets page wordpress loads some javascript which handles the transfer via AJAX. Nov 24, 2012 at 14:15
  • @MridulAggarwal I thought so...Im wondering if theres a jquery solution for this. Ive seen selectboxes which enables other things when options are selected but Im not sure if this can be made on wp admin selectboxes too. Thanks for your reply!
    – Madalin
    Nov 24, 2012 at 14:39

1 Answer 1


This would have to be fully coded and tested, but I think the roadmap is:

Deregister the Default Meta Box and Make a Custom One

@MikeSchinkel answer to this question is very detailed and thoughtful: Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?

In that case, it is for duplicating the Pages Template Meta Box into Posts.

This other Q&A ( How To Change Custom Taxonomy To Radio Buttons ) provides an example of replacing the Taxonomies Meta Box.

Add Ajax to the Custom Templates Meta Box

In this answer, there's an example of custom meta box that runs an Ajax call, that in turn makes a database query to modify an attachment parent.

To do the Page Template live switch, it would be a matter of modifying the table wp_postmeta where the current template value is stored.

The meta_key name is _wp_page_template and its value the template file name.

results of query wp_postmeta _wp_page_template

  • Thanks for your complete answer. I`ll give it a try and see if is really working!
    – Madalin
    Nov 25, 2012 at 9:57
  • Nice, and if you build a working code please publish as an answer here :)
    – brasofilo
    Nov 25, 2012 at 11:48

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.