0

Is it possible to enable a second content area in the edit screen if a certain template is chosen?

I have seen plugins like the second section plugin but that enables it for all pages I would like to only have the second section if a certain page template is chosen for a page.

2

You could add a metabox for your second content section, then hide it with a bit of javascript if the current template isn't a specific template:

current_template = jQuery('#page_template').val();
if( current_template != 'my-special-template.php' ){
    jQuery('#_your_meta_box_id').hide();
}

then bind a function to the change event of the template dropdown and show it when a specific template is selected:

jQuery('#page_template').change(function(){
    selected_template = jQuery(this).val();
    if( selected_template == 'my-special-template.php' ){
        jQuery('#_your_meta_box_id').show();
    }
});
  • Thanks that is a nice idea, my only concern would be users without JavaScript on. – Lee Sep 9 '11 at 8:05
  • @Lee - without javascript the only way to do it would be to require that they select a template then save the post before they're able to see the additional content section. the visual editor doesn't work and there's no way to add images to a post without js anyway. – Milo Sep 9 '11 at 14:46
  • |Good point I will try it out and see how I get on - thanks :) – Lee Sep 9 '11 at 15:38

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.