Add Field into the WordPress Setting page

add this to functions.php file
//added for show/hide facility for booking form

$new_general_setting = new new_general_setting();

class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'show_booking_form', 'esc_attr' );
add_settings_field('fav_color', '<label for="show_booking_form">'.__('Show Booking Form?' , 'show_booking_form' ).'</label>' , array(&$this, 'fields_html') , 'general' );
}
function fields_html() {
$value = get_option( 'show_booking_form', '' );
if($value != "")
$tmpcheckstr =" checked";
else
{
$tmpcheckstr =" ";
$value = "show the form";
}
echo '<input type="checkbox" id="show_booking_form" name="show_booking_form" value="' . $value . '" '.$tmpcheckstr.' /> Yes';
}
}
Add this code into Your theme file
<?php $bookoption = get_option('show_booking_form');
if($bookoption){?>
<div id="contactusfomr" style="float:left;width:270px;">
<?php echo do_shortcode( '[contact-form-7 id="146" title="Contact form 1"]'); ?>// remove this line and Add your  Code here
</div>    <?php } ?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s