I'm creating a plugin that will store some simple layouts to be used in shortcodes.

The shortcode usage will be similar to [shortcode layout="name"]

With this mind I'll need to store each layout in the array as a key/value setup

Key = layout name

Value = layout markup

I'd like to store these in settings however I'm not sure how to go about it. How can I create a settings page that allows addition and editing. Normally my settings pages use code as follows and automatically wires into the api.

<input type="text" id="company_name" name="wpv_settings[company_name]" value="<?php echo $wpv_settings['company_name']; ?>" class="regular-text" />

However, I can't find how to go about this when the setting is an array of key/values.

Can anyone point me in the right direction of how this would be done?


Since the layout names are dynamic, perhaps it's better to store them in a numerically indexed nested array? Something like:

wpv_settings[layouts][0][name] = $key
wpv_settings[layouts][0][markup] = $value

wpv_settings[layouts][1][name] = $key
wpv_settings[layouts][1][markup] = $value


| improve this answer | |
  • Can I automate the creation/updating of the options for this using Wordpress settings register? <input type="text" id="company_name0" name="wpv_settings[layouts][0][name]" value="<?php echo $wpv_settings[layouts][0][name]; ?>" class="regular-text" /> – WDuffy Jun 20 '12 at 8:52

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.