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
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.