I'm not a web developer and have been following a tutorial on how to add options to a simple self-written theme.

In functions.php I've added the following code:

$themename = "Theme Name";
$shortname = "sn";
$options = array (

    array(  "name" => "Price"),

    array(  "type" => "open"),

    array(  "name" => "Price",
            "desc" => "Enter a price to sell your item for.",
            "id" => $shortname."_price",
            "std" => "",
            "type" => "text"),

    array(  "type" => "close"),


In index.php I have the following code

    <?php if ($sn_price) { ?>
        <h2><? echo "$" . $sn_price; ?></h2>
    <? } else { ?>
        <h2>Price on registration of interest.</h2>
    <? } ?>

The theme options are available in the back end, and I have saved the price in the theme options.

The price is saved when I return to the back end to check the options, but $sn_price displays as empty on the front end.

Any ideas why?

Edit: Here is functions.php

  • 1
    You need to show the code where/how the options are actually saved.
    – Wyck
    Apr 4, 2012 at 5:31

1 Answer 1


Steve you're doing it wrong.

WordPress provides Settings API that should be used for settings pages. If you aren't familiar with Settings API see great tutorial by Chip Bennett - Incorporating the Settings API in WordPress Themes.

  • I think the tute I was following applies to a Wordpress version older than 3 perhaps...
    – Steve
    Apr 4, 2012 at 8:51
  • Settings API was introduced in WordPress 2.7, but I think most tutorials didn't used it back then.
    – Mamaduka
    Apr 4, 2012 at 8:56
  • Does register_setting() have to be declared after certain other functions? I am getting the error "Fatal error: Call to undefined function register_setting() in /themes/themename/functions.php on line 73"
    – Steve
    Apr 5, 2012 at 3:46
  • 1
    register_settings() should be called on admin_init, also check Twenty Eleven's theme-options.php file for more examples.
    – Mamaduka
    Apr 5, 2012 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.