Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?php
$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

share|improve this question
1  
You need to show the code where/how the options are actually saved. –  Wyck Apr 4 '12 at 5:31
    
Thanks, added a pastebin link to functions.php –  Steve Apr 4 '12 at 7:01

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.

share|improve this answer
    
I think the tute I was following applies to a Wordpress version older than 3 perhaps... –  Steve Apr 4 '12 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 '12 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 '12 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 '12 at 8:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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