treehouse : what would you like to learn today?
Web Design Web Development iOS Development

WP Global Custom Fields Code

  • I found a cool bit of code in the Digging Into Wordpress about using Global Custom Fields. It requires inserting a bit of code into your functions.php file:

    <?php 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>Amazon ID:</strong><br />
    <input type=\"text\" name=\"amazonid\" size=\"45\"
    value=\"<?php echo get_option('amazonid'); ?>\" />
    </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=\"amazonid\" />
    </form>
    </div>

    <?php } ?>


    Unfortunately, it produces this error when I try and view the wp-admin:
    Parse error: syntax error, unexpected '<' in [domain redacted]/html/wp-content/themes/hawpTheme/hawpTheme/functions.php on line 7


    Line 7, in the PHP file, being the first line of code of the above snippet. There might just be something wrong syntax-wise?
  • It may help if you were to post the whole code.