How to create a “universal” custom field in Wordpress?

(wordpress version 3.4)

Ok, here is what I am trying to do:

Create a page called Custom Fields that the user will never see. Its easy for the client to add to custom fields. He will constantly need to change these custom fields weekly / monthly.

I need these custom fields to appear inside the header, footer, or sidebars so that they are universal on all pages.

Do you know the right way to tweak the code so that I can achieve this?

Thanks!

+4
source share
2 answers

Since custom fields are for each post, I would recommend using the Options metadata store instead. This way you can change the values ​​from the admin panel, which is more convenient and consistent.

This tutorial shows how you can add this functionality in WP

//Custom Theme Settings add_action('admin_menu', 'add_gcf_interface'); function add_gcf_interface() { add_options_page('Global Custom Fields', 'Global Custom Fields', '8', 'functions', 'editglobalcustomfields'); } function editglobalcustomfields() { ?> <div class='wrap'> <h2>Global Custom Fields</h2> <form method="post" action="options.php"> <?php wp_nonce_field('update-options') ?> <p><strong>My Name:</strong><br /> <input type="text" name="myname" size="45" value="<?php echo get_option('myname'); ?>" /></p> <p><strong>Amazon ID:</strong><br /> <input type="text" name="amazonid" size="45" value="<?php echo get_option('amazonid'); ?>" /></p> <p><strong>Today Featured Website:</strong><br /> <input type="text" name="todaysite" size="45" value="<?php echo get_option('todaysite'); ?>" /></p> <p><strong>Welcome Text:</strong><br /> <textarea name="welcomemessage" cols="100%" rows="7"><?php echo get_option('welcomemessage'); ?></textarea></p> <p><input type="submit" name="Submit" value="Update Options" /></p> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="myname,amazonid,todaysite,welcomemessage" /> </form> </div> <?php } 
+14
source

With Cleric code, I got an error while saving a variable. He kept everything in order, but there was an error in the fact that the code was out of date.

Then I found this page Handling plugin options in WordPress 2.8 with register_setting () , and now it works great in WP version 3.5.

0
source

All Articles