I'd like to have a custom field interface show up only when a certain template is assigned to a particular WordPress page.
Any ideas?
|
I'd like to have a custom field interface show up only when a certain template is assigned to a particular WordPress page. Any ideas? |
|||||
|
|
The best way to approach this situation is via JavaScript. That way, whenever the selected value changes, you can instantly hide/show the related metabox. Use
The script itself, which requires jQuery, simply hides or shows a metabox based on the selected value in the page template dropdown list. In this example, I'm only showing the metabox for post thumbnails in case the default page template is selected:
And, just for fun, here's a shorter, less verbose, version of the same script:
|
|||||||
|