Skip to content

Instantly share code, notes, and snippets.

@vimes1984
Last active August 29, 2015 14:12
Show Gist options
  • Save vimes1984/f225ddd856576474902d to your computer and use it in GitHub Desktop.
Save vimes1984/f225ddd856576474902d to your computer and use it in GitHub Desktop.
A simple options page for a wordpress theme to be dupmed into the functions file, it's here becuase I always have to google on how to do this
<?php
/**
* Add's menu page and submenu page
*/
function add_theme_menu_pages(){
add_menu_page( 'Main options', 'Theme settings', 'manage_options', 'theme_options_func', 'theme_options_func');
add_submenu_page( 'theme_options_func', 'Additional Theme settings', 'Additional Theme settings', 'manage_options', 'additional-theme-options', 'additional_theme_options_func' );
}
/**
* Add's a submenu to menu above
*/
function additional_theme_options_func(){
echo "<h2>Not in use please visit <a href='admin.php?page=theme_options_func'>Here</a></h2>";
}
/**
* Registers our settings and displays two input boxes..
* also checks for a hidden input value so we can update on save
*/
function theme_options_func(){
if (isset($_POST["update_settings"])) {
// Do the saving
$footer_text_option = esc_attr($_POST["footer_text_option"]);
update_option("footer_text_option", $footer_text_option);
$footer_link = esc_attr($_POST["footer_link"]);
update_option("footer_link", $footer_link);
?>
<div id="message" class="updated">Settings saved</div>
<?php
}else{
$footer_text_option = get_option("footer_text_option");
$footer_link = get_option("footer_link");
}
?>
<div class="wrap">
<?php screen_icon('themes'); ?> <h2>General Theme options</h2>
<h4>Please keep all these settintgs filled...</h4>
<form method="POST" action="">
<input type="hidden" name="update_settings" value="Y" />
<table class="form-table shopagesettings">
<tr valign="top">
<th scope="row">
<label for="footer_text_option">
Footer &copy; text:
</label>
</th>
<td>
<input type="text" name="footer_text_option" placeholder="Footer copyright text" value="<?php echo $footer_text_option; ?>">
</td>
</tr>
<tr valign="top" class="lasttr">
<th scope="row">
<label for="footer_link">
Footer &copy; Link:
</label>
</th>
<td>
<input type="text" name="footer_link" placeholder="Footer copyright link" value="<?php echo $footer_link; ?>">
</td>
</tr>
</table>
<input type="submit" value="Save settings" class="button-primary"/>
</form>
</div>
<?php
}
add_action( 'admin_menu', 'add_theme_menu_pages' );
/*
Get options like on theme pages like so:
$footer_text_option = get_option("footer_text_option");
$footer_link = get_option("footer_link");
then display like so:
<?php echo $footer_link ; ?>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment