Last active
August 29, 2015 13:55
-
-
Save technoknol/8708139 to your computer and use it in GitHub Desktop.
Wordpress Create Custom Theme Options Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* * | |
* Created By : TechnoKnol (Nick Name ) | |
* Created On : 30th January 2014 | |
* Blog : http://technoknol.blogspot.com | |
* | |
* */ | |
/************************ | |
* | |
* Add this code to your theme's function.php file. | |
* | |
***************/ | |
/************ Get theme options *************************************/ | |
add_action('admin_menu' , 'add_appearance_menu') ; | |
function add_appearance_menu() { | |
add_theme_page('My Theme Options','Theme_Options',7,'theme_options','theme_page_option'); | |
} | |
function theme_page_option() { | |
get_template_part('theme_options'); // This name and below file name should be same. | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* * | |
* Created By : TechnoKnol (Nick Name ) | |
* Created On : 30th January 2014 | |
* Blog : http://technoknol.blogspot.com | |
* | |
* Put this file in your wordpress Theme's directory. ( Wordpress-Install-Dir/wp-content/themes/your-theme-name/) | |
* (Beside functions.php, header.php, footer.php etc...) | |
* */ | |
global $theme_options ; | |
global $theme_options_defaults; | |
$theme_options_defaults = array ( | |
'twitter_uid' => '#', | |
'facebook_uid' => '#', | |
'linkdin_uid' => '#', | |
'gplus_uid' => '#', | |
'foot_copyright' => '2013 Lorem Ipsum Limited', | |
'contact_num' => 'XXXXXXXXX', | |
'contact_mail' => '[email protected]', | |
'contact_fax' => 'XXXXXXXXX', | |
'head_con_no' => 'XXXXXXXXX', | |
'name_line_1' => 'Lorem Ipsum', | |
'name_line_2' => 'Dolar Simet', | |
'add_line_1' => '5786. 59th Office Box 15', | |
'add_line_2' => 'Lorem CA, 519458', | |
); | |
if(isset($_POST['submit'])){ | |
$new_values = array( | |
'twitter_uid' => htmlentities($_POST['twitter_uid'], ENT_QUOTES), | |
'facebook_uid' => htmlentities($_POST['facebook_uid'], ENT_QUOTES), | |
'linkdin_uid' => htmlentities($_POST['linkdin_uid'], ENT_QUOTES), | |
'gplus_uid' => htmlentities($_POST['gplus_uid'], ENT_QUOTES), | |
'foot_copyright' => htmlentities($_POST['foot_copyright'], ENT_QUOTES), | |
'contact_num' => htmlentities($_POST['contact_num'], ENT_QUOTES), | |
'contact_mail' => htmlentities($_POST['contact_mail'], ENT_QUOTES), | |
'contact_fax' => htmlentities($_POST['contact_fax'], ENT_QUOTES), | |
'head_con_no' => htmlentities($_POST['head_con_no'], ENT_QUOTES), | |
'name_line_1' => htmlentities($_POST['name_line_1'], ENT_QUOTES), | |
'name_line_2' => htmlentities($_POST['name_line_2'], ENT_QUOTES), | |
'add_line_1' => htmlentities($_POST['add_line_1'], ENT_QUOTES), | |
'add_line_2' => htmlentities($_POST['add_line_2'], ENT_QUOTES), | |
'default' => htmlentities($_POST['default'], ENT_QUOTES), | |
); | |
if ($new_values['default'] == true ) { | |
foreach ($new_values as $key=>$value) { | |
if (empty($value) ) { | |
$new_values[$key] = $theme_options_defaults[$key] ; | |
} | |
} | |
} | |
update_option('theme_options', $new_values); | |
$theme_options = $new_values; | |
} | |
if(get_option('theme_options')){ | |
$theme_options = get_option('theme_options'); | |
} | |
else{ | |
add_option('theme_options', $theme_options_defaults)); | |
$theme_options = get_option('theme_options'); | |
} | |
?> | |
<div class="wrap"> | |
<h2>Theme Options</h2><br/> | |
<form action="" method="post" enctype="multipart/form-data"> | |
<table> | |
<tr> | |
<td><label for="default">Default: </label></td> | |
<td><input id="default" type="checkbox" name="default" value="true" /></td> | |
<td><label class="description" for="default"><?php _e('Fill Default values '); ?><small>Empty fields will be filled with Defaults</small></label></td> | |
</tr> | |
<tr> | |
<td><label for="twitter_uid">Twitter: </label></td> | |
<td><input id="twitter_uid" type="text" name="twitter_uid" value="<?php echo $theme_options['twitter_uid']; ?>" /></td> | |
<td><label class="description" for="twitter_uid"><?php _e('Enter your Twitter URL'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="facebook_uid">Facebook: </label></td> | |
<td><input id="facebook_uid" type="text" name="facebook_uid" value="<?php echo $theme_options['facebook_uid']; ?>" /></td> | |
<td><label class="description" for="facebook_uid"><?php _e('Enter Your Facebook URL'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="linkdin_uid">Linked In: </label></td> | |
<td><input id="linkdin_uid" type="text" name="linkdin_uid" value="<?php echo $theme_options['linkdin_uid']; ?>" /></td> | |
<td><label class="description" for="linkdin_uid"><?php _e('Enter LinkedIn URL'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="gplus_uid">Google+ : https://plus.google.com/</label></td> | |
<td><input id="gplus_uid" type="text" name="gplus_uid" value="<?php echo $theme_options['gplus_uid']; ?>" /></td> | |
<td><label class="description" for="gplus_uid"><?php _e('Enter google+ Profile URL'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="foot_copyright">Copyright Text: </label></td> | |
<td><input id="foot_copyright" type="text" name="foot_copyright" value="<?php echo $theme_options['foot_copyright']; ?>" /></td> | |
<td><label class="description" for="foot_copyright"><?php _e('Footer Copyright Text'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="contact_num">Footer Contact Number: </label></td> | |
<td><input id="contact_num" type="text" name="contact_num" value="<?php echo $theme_options['contact_num']; ?>" /></td> | |
<td><label class="description" for="contact_num"><?php _e('Footer Contact Numnber'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="contact_mail"> Email: </label></td> | |
<td><input id="contact_mail" type="text" name="contact_mail" value="<?php echo $theme_options['contact_mail']; ?>" /></td> | |
<td><label class="description" for="contact_mail"><?php _e('Email Address'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="contact_fax">Fax: </label></td> | |
<td><input id="contact_fax" type="text" name="contact_fax" value="<?php echo $theme_options['contact_fax']; ?>" /></td> | |
<td><label class="description" for="contact_fax"><?php _e('Fax'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="head_con_no">Header Contact No: </label></td> | |
<td><input id="head_con_no" type="text" name="head_con_no" value="<?php echo $theme_options['head_con_no']; ?>" /></td> | |
<td><label class="description" for="head_con_no"><?php _e('Header Contact no'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="name_line_1">Name Line 1 : </label></td> | |
<td><input id="name_line_1" type="text" name="name_line_1" value="<?php echo $theme_options['name_line_1']; ?>" /></td> | |
<td><label class="description" for="name_line_1"><?php _e('Name Line 1 '); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="name_line_2">Name Line 2: </label></td> | |
<td><input id="name_line_2" type="text" name="name_line_2" value="<?php echo $theme_options['name_line_2']; ?>" /></td> | |
<td><label class="description" for="name_line_2"><?php _e('name_line_2'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="add_line_1">Address Line 1: </label></td> | |
<td><input id="add_line_1" type="text" name="twi" value="<?php echo $theme_options['add_line_1']; ?>" /></td> | |
<td><label class="description" for="add_line_1"><?php _e('Address Line 1'); ?></label></td> | |
</tr> | |
<tr> | |
<td><label for="add_line_2">Address Line 2: </label></td> | |
<td><input id="add_line_2" type="text" name="add_line_2" value="<?php echo $theme_options['add_line_2']; ?>" /></td> | |
<td><label class="description" for="add_line_2"><?php _e('Enter your Facebook URL'); ?></label></td> | |
</tr> | |
<tr> | |
<td colspan="2"><br/><input type="submit" value="Update Options" class="button-primary save"name="submit" /> | |
</td> | |
</tr> | |
</table> | |
</form> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment