When I create a custom field and associate it to a custom page template, it doesn't show in the post editor screen until I click save (draft / publish).

Ideally, the custom field should show when I select the page template from the dropdown, without having to save anything. Can anyone suggest how I would achieve this desired behavior?



  • 1
    How are you creating this Custom Field? – brasofilo Jul 25 '12 at 10:57
  • Without knowing how you created a custom field, we really can't help. Code snippet? – Dan Jan 15 '13 at 7:08

If you added the Custom field only to a certain page template it won't show on default edit screen when it stared or when you creating a new page because the new page isn't associate with the page template yet. And when you save it shows because now the page template is added to the post.

One solution, you can use some jquery coding if you want to add the meta box when code you select the page template from dropdown.

  • That makes sense. I guess I could have js listen out for when the template drop-down is changed, and then initiate the save_post action. Does that sound like a sensible way of achieving this? – bob Jul 24 '12 at 16:55
  • Hum, just looking through the codex and noticed the add_post_meta function. Was this what you were suggesting? – bob Jul 24 '12 at 17:12
  • yes, i was thinking of adding a meta box on fly using jquery. Then save the post meta when you save the page using save_post action. – Sisir Jul 24 '12 at 17:19
  • But you can just add the metabox using php and use it on the page template. So, it wont show on front end for normal page template if someone puts value on it. That will save you from writing jquery. – Sisir Jul 24 '12 at 17:20
  • You could makes meta boxes available for all pages and give them ids which you hide with css. Then once you know what template is being used or has just been chosen; show the appropriate meta boxes with js. – user10106 Jan 22 '14 at 19:43

If you want the field to show up dynamically after choosing a template, then you will need to add some JavaScript to show / hide the meta box depending on the page template selected.

Your Answer

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

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