Hi folks, I'm having a lot of trouble with my Wordpress theme's JS currently. It's a mixture of PHP and JS but I think it's the JS that's the problem. My theme, F2 (http://srinig.com/wordpress/) has the ability to turn off each of its two sidebars, left or right.

It's the right one I'd like to turn off but only for certain pages if possible. I know full well that there's an option to toggle this within this code here but I need to adapt it so that I can select future pages to have right sidebar on or off at will.

Here's the code, I've tried to work out a solution looking at template conditionals etc but to no avail. I've e-mailed the author as well. Sorry if this turns out to be a PHP problem, the two are mixed in my functions.php which I'm posting up. I'm pretty sure it's the JQuery bit that needs adjusting.

Thanks for your help.

Code:
<?php

add_action( 'after_setup_theme', 'f2_setup' );

function f2_setup()
{
	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => __( 'Primary Navigation', 'f2' ),
	) );
}

function f2_nav_menu()
{ ?>
<ul>
	<li><a href="<?php echo get_option('home'); ?>"><?php _e('Home', 'f2') ?></a></li>
	<?php wp_list_pages('title_li=&depth=2&sort_column=menu_order&exclude='.f2_option('hmenu_exclude')) ?>
	<li class="hmenu_rss"><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('Feed', 'f2') ?></a></li>
</ul>
<?php
}


add_theme_support( 'automatic-feed-links' );

if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'name' => 'Left Sidebar'
	));
	register_sidebar(array(
		'name' => 'Right Sidebar'
	));
}

$themename = "F2";
$shortname = "f2";
$version = "1.1.1";

load_theme_textdomain ('f2', get_template_directory().'/languages');

$options = array (
	'header' => array (
		'name' => __('Header', 'f2'),
		'type' => 'section'
	),
	'header_img' => array (
		'name' => __('Header background image?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'off',
		'category' => 'header'
	),
	'header_img_url' => array(
		'name' => __('Header background image URL', 'f2'),
		'desc' => __('Tip: <a target="_blank" href="media-new.php">Upload your image here</a> and grab the url.', 'f2'),
		'type' => 'text',
		'default' => '',
		'category' => 'header',
		'th_class' => 'header_img_dependent',
		'class' => 'url'
	),		
	'header_img_repeat' => array(
		'name' => __('Repeat header background image?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'header',
		'th_class' => 'header_img_dependent'
	),
	'header_textlogo' => array(
		'name' => __('Show blog title & tagline in header?', 'f2'),
		'desc' => __('You may uncheck this option if you use a background image as logo.', 'f2'),
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'header',
		'th_class' => 'header_img_dependent'
	),
	'header_height' => array(
		'name' => __('Header height', 'f2'),
		'type' => 'text',
		'desc' => '',
		'default' => '90',
		'category' => 'header',
		'class' => 'pixels'
	),
	'header_bg_color' => array(
		'name' => __('Header background color', 'f2'),
		'desc' => '',
		'type' => 'text',
		'default' => '#6d97b7',
		'category' => 'header',
		'class' => 'colorinput'
	),
	'header_title_color' => array(
		'name' => __('Blog title font color', 'f2'),
		'type' => 'text',
		'desc' => '',
		'default' => '#d0e0f0',
		'category' => 'header',
		'class' => 'colorinput',
	),
	'header_desc_color' => array(
		'name' => __('Blog tagline font color', 'f2'),
		'type' => 'text',
		'desc' => '',
		'default' => '#ffffff',
		'category' => 'header',
		'class' => 'colorinput',
	),
	'hmenu' => array(
		'name' => __('Show horizontal menu?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'header',
		'class' => ''
	),
	'hmenu_exclude' => array(
		'name' => __('Pages to be excluded in horizontal menu', 'f2'),
		'desc' => __('Comma separated page IDs', 'f2'),
		'type' => 'text',
		'default' => '',
		'category' => 'header',
		'class' => '',
		'th_class' => 'hmenu_dependent'
	),
	'hmenu_rss' => array(
		'name' => __('Show RSS feed link in horizontal menu?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'header',
		'class' => '',
		'th_class' => 'hmenu_dependent'
	),
	array (
		'type' => 'section_close'
	),
	'sidebar' => array (
		'name' => __('Sidebar', 'f2'),
		'type' => 'section'
	),
	'sidebar_l' => array(
		'name' => __('Show left sidebar?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'sidebar'
	),
	'sidebar_l_width' => array(
		'name' => __('Left sidebar width?', 'f2'),
		'desc' => '',
		'type' => 'text',
		'default' => '200',
		'category' => 'sidebar',
		'class' => 'pixels',
		'th_class' => 'sidebar_l_dependent'
	),
	'sidebar_l_fontsize' => array(
		'name' => __('Left sidebar fontsize', 'f2'),
		'desc' => '',
		'type' => 'select',
		'options' => array(
			array('0.85em', __('small', 'f2')),
			array('1em', __('medium', 'f2')),
			array('1.15em', __('large', 'f2'))
		),
		'default' => '1em',
		'category' => 'sidebar',
		'class' => 'fontselect',
		'th_class' => 'sidebar_l_dependent'
	),
	'sidebar_r' => array(
		'name' => __('Show right sidebar?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'sidebar'
	),
	'sidebar_r_width' => array(
		'name' => __('Right sidebar width?', 'f2'),
		'desc' => '',
		'type' => 'text',
		'default' => '200',
		'category' => 'sidebar',
		'class' => 'pixels',
		'th_class' => 'sidebar_r_dependent'
	),
	'sidebar_r_fontsize' => array(
		'name' => __('Right sidebar fontsize', 'f2'),
		'desc' => '',
		'type' => 'select',
		'options' => array(
			array('0.85em', __('small', 'f2')),
			array('1em', __('medium', 'f2')),
			array('1.15em', __('large', 'f2'))
		),
		'default' => '1em',
		'category' => 'sidebar',
		'class' => 'fontselect',
		'th_class' => 'sidebar_r_dependent'
	),
	array (
		'type' => 'section_close'
	),
	'posts' => array (
		'name' => __('Blog posts', 'f2'),
		'type' => 'section'
	),
	'content_fontsize' => array(
		'name' => __('Blog post text size', 'f2'),
		'desc' => '',
		'type' => 'select',
		'options' => array(
			array('0.85em', __('small', 'f2')),
			array('1em', __('medium', 'f2')),
			array('1.15em', __('large', 'f2'))
		),
		'default' => '1em',
		'category' => 'posts'
	),
	'show_author' => array(
		'name' => __('Show post author?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'off',
		'category' => 'posts'
	),
	'show_cat' => array(
		'name' => __('Show post category?', 'f2'),
		'desc' => '',
		'type' => 'checkbox',
		'default' => 'on',
		'category' => 'posts'
	),
	'archive_posts' => array (
		'name' => __('Full post or excerpt in archive pages?', 'f2'),
		'desc' => __('Displaying only excerpt in archive pages is a better SEO practice.', 'f2'),
		'type' => 'select',
		'options' => array (
			array('full', __('Full post', 'f2')),
			array('excerpt', __('Only excerpt', 'f2'))
		),
		'default' => 'excerpt',
		'category' => 'posts'
	),

	array (
		'type' => 'section_close'
	),
	'footer' => array (
		'name' => __('Footer', 'f2'),
		'type' => 'section'
	),
	'footer_text' => array(
		'name' => __('Footer text', 'f2'),
		'desc' => '',
		'type' => 'textarea',
		'default' => '&copy;&nbsp;'.date('Y').'&nbsp;'.get_bloginfo('name'),
		'category' => 'footer'
	),
	array (
		'type' => 'section_close'
	),
	'general' => array (
		'name' => __('General options', 'f2'),
		'type' => 'section'
	),
	'rounded_corners' => array (
		'name' => __('Rounded corners?', 'f2'),
		'desc' => __('Rounded corners add to the fluid nature of the theme. Note that this will add non-standard CSS code.', 'f2'),
		'type' => 'checkbox',
		'default' => 'off',
	),
	array (
		'type' => 'section_close'
	),
);

function f2_add_admin()
{
	global $themename, $shortname, $options;
	if( $_GET['page'] == basename(__FILE__) && isset($_REQUEST['action']) ) {
		if(__('Save changes', 'f2') == $_REQUEST['action']) {
			foreach($options as $key => $option) {
				
				$id = $shortname.'_'.$key;
				
				if($option['type'] == 'checkbox')
					$value = $_REQUEST[$id]?'on':'off';
				else
					$value = isset($_REQUEST[$id])?stripslashes($_REQUEST[$id]):$option['default'];
				
				update_option($id, $value);
				
			}
			header("Location: themes.php?page=functions.php&saved=true");
			die;
		}
		else if(__('Reset to defaults', 'f2') == $_REQUEST['action']) {
			foreach($options as $key => $value)
				delete_option($shortname.'_'.$key);
			header("Location: themes.php?page=functions.php&reset=true");
			die;
		}
		
	}
    add_theme_page($themename.' '.__('Settings', 'f2'), $themename.' '.__('Settings', 'f2'), 'edit_themes', basename(__FILE__), 'f2_admin');

}

function f2_admin() {
	global $themename, $shortname, $version, $options;
    $options = $options;	

    if ( isset($_REQUEST['saved']) ) echo '<div id="message" class="updated fade"><p><strong>'.__('Settings saved', 'f2').'</strong></p></div>';
    if ( isset($_REQUEST['reset']) ) echo '<div id="message" class="updated fade"><p><strong>'.__('Settings reset', 'f2').'</strong></p></div>';

?>
<div class="wrap">
<h2><?php echo $themename.' '; _e('Settings', 'f2'); ?></h2>
<div id="poststuff" class="metabox-holder">
<div class="stuffbox">
<div class="inside">
<table><tr>
<td style="width:60%;vertical-align:top;">
<p><strong><?php echo $themename; ?> WordPress theme</strong> <?php _e('version', 'f2'); ?> <strong><?php echo $version; ?></strong>. <?php printf(__('Visit <a href="%s">theme page</a>', 'f2'), 'http://srinig.com/wordpress/themes/f2/'); ?>. <?php printf(__('View <a href="%s">readme</a>', 'f2'), get_bloginfo('template_url').'/readme.html'); ?>.</p>
<p>
<a href="#f2_header"><?php _e('Header Settings', 'f2'); ?></a>&nbsp;|
<a href="#f2_sidebar"><?php _e('Sidebar Settings', 'f2'); ?></a>&nbsp;|
<a href="#f2_posts"><?php _e('Posts Settings', 'f2'); ?></a>&nbsp;|
<a href="#f2_footer"><?php _e('Footer Settings', 'f2'); ?></a>&nbsp;|
<a href="#f2_general"><?php _e('General Settings', 'f2'); ?></a>
</p>
</td>
<td style="width:30%;vertical-align:top;">
<div style="max-width:240px;float:right;">
<p><?php _e('If you enjoy the theme, you can make a donation and support development. Thank you!', 'f2'); ?></p>
<div style="text-align:center;"><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="7622318">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form></div>
</div>
</td>
</tr></table>
</div>
</div>
<form method="post">
<?php
   
	foreach($options as $key => $option) {

		$id = $shortname.'_'.$key;
		if($option['type'] != 'section' && $option['type'] != 'section_close')
			$value = get_option($id, $option['default']);
		
		switch ($option['type'] ) {
			case "section": { ?>
<div class="stuffbox">
<h3 id="<?php echo $shortname.'_'.$key; ?>"><?php echo $option['name']; ?></h3>
<div class="inside">
<table class="form-table">
<?php break; }
			case "section_close": { ?>
</table>
</div>
</div>
<?php break; } 
			case 'text': { ?>
<tr<?php if($option['th_class']) echo ' class="'.$option['th_class'].'"'; ?>>
	<th scope="row"><label for="<?php echo $id; ?>"><?php echo $option['name']; ?></label></th>
	<td>
		<input type="text" class="<?php echo $option['class']; ?>"" name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="<?php echo $value; ?>"<?php if($option['class'] == 'colorinput') echo ' size="7"'; elseif($option['class'] == 'pixels') echo ' size="3"'; elseif($option['class'] == 'url') echo ' size="60"'; ?> />
		<?php if($option['class'] == 'pixels') echo "<span style='font-size:12px;'>px</span>"; ?>
		<?php if($option['class'] == 'colorinput') { ?>
		<a class="colorclose" style="cursor:pointer;"><?php _e('Close colorpicker', 'f2'); ?></a>
		<div id="colorpicker-<?php echo $key; ?>" class="colorpicker"></div>
		<?php } if($option['desc']) {
			if ($option['class'] == 'url')
				echo "<br />";
			echo "<span class='description' style='font-size:10px'>".$option['desc']."</span>"; 
		} ?>
		
	</td>
</tr>
<?php break; }
			case 'checkbox': { ?>
<tr<?php if($option['th_class']) echo ' class="'.$option['th_class'].'"'; ?>>
	<th scope="row"><label for="<?php echo $id; ?>"><?php echo $option['name']; ?></label></th>
	<td>
		<input type="checkbox" class="<?php echo $option['class']; ?>" name="<?php echo $id; ?>" id="<?php echo $id; ?>"<?php if($value == 'on') echo ' checked="checked"'; ?> />
		<?php if($option['desc']) echo "<span class='description' style='font-size:10px'>".$option['desc']."</span>"; ?>
	</td>
</tr>
<?php break; }
			case 'select': { ?>
<tr<?php if($option['th_class']) echo ' class="'.$option['th_class'].'"'; ?>>
	<th scope="row"><label for="<?php echo $id; ?>"><?php echo $option['name']; ?></label></th>
	<td>
		<select class="<?php echo $option['class']; ?>" name="<?php echo $id; ?>" id="<?php echo $id; ?>">
		<?php foreach ($option['options'] as $sel_opts) {
			echo '<option value="'.$sel_opts[0].'"';
			if($value == $sel_opts[0])
				echo ' selected="selected"';
			echo '>'.$sel_opts[1].'</option>';
		} ?>
		</select>
		<?php if($option['desc']) echo "<span class='description' style='font-size:10px'>".$option['desc']."</span>"; ?>
	</td>
</tr>
<?php break; }
			case 'textarea': { ?>
<tr<?php if($option['th_class']) echo ' class="'.$option['th_class'].'"'; ?>>
	<th scope="row"><label for="<?php echo $id; ?>"><?php echo $option['name']; ?></label></th>
	<td>
		<textarea class="<?php echo $option['class']; ?>" name="<?php echo $id; ?>" id="<?php echo $id; ?>" style="width:100%; height:6em;"><?php echo $value; ?></textarea>
		<?php if($option['desc']) echo "<br /><span class='description' style='font-size:10px'>".$option['desc']."</span>"; ?>
	</td>
</tr>
<?php break; } 
		}
	}
?> 
<input name="action" value="<?php _e('Save changes', 'f2'); ?>" class="button-primary" type="submit">
<input name="action" value="<?php _e('Reset to defaults', 'f2'); ?>" class="button" type="submit">
</form>
</div>
</div>
<?php
}

add_action('admin_menu', 'f2_add_admin');



function f2_head()
{
	global $shortname, $options;
	
	foreach($options as $key => $option) {
		if($option['type'] != 'section' && $option['type'] != 'section_close')
			$$key = get_option($shortname.'_'.$key, $option['default']);
	}
	if($header_img == 'on') {
		$style['#header']['background-image'] = "url('{$header_img_url}')";
		if($header_img_repeat == 'off') 
			$style['#header']['background-repeat'] = "no-repeat";
	}
	if($header_bg_color && $header_bg_color != '#')
		$style['#header']['background-color'] = $header_bg_color;
	if($header_textlogo == 'off')
		$style['#headerlogo']['visibility'] = 'hidden';
	if($header_height && $header_height != 90)
		$style['#header']['height'] = $header_height.'px';
	if($hmenu == 'off')
		$style['#hmenu']['display'] = 'none';
	if($hmenu_rss == 'off')
		$style['#hmenu li.hmenu_rss']['display'] = 'none';
	if($header_title_color && $header_title_color != '#')
		$style['#headerlogo h1 a']['color'] = $header_title_color;
	if($header_desc_color && $header_desc_color != '#')
		$style['#headerlogo div.description']['color'] = $header_desc_color;
	if($sidebar_r == 'off') {
		$style['#container']['padding-right'] = 0;
		$style['#wrapper']['border-right'] = 0;
		$style['#wrapper']['margin-right'] = 0;
	}
	else if($sidebar_r_width) {
		$style['#container']['padding-right'] = ($sidebar_r_width + 40).'px';
		$style['#wrapper']['border-right-width'] = ($sidebar_r_width + 40).'px';
		$style['#wrapper']['margin-right'] = '-'.($sidebar_r_width + 40).'px';
		$style['#sidebar_right'] = array (
			'width' => $sidebar_r_width.'px',
			'margin-right' => '-'.($sidebar_r_width + 40).'px',
		); 
	}	
	if($sidebar_l == 'off') {
		$style['#container']['padding-left'] = 0;
		$style['#wrapper']['border-left'] = 0;
		$style['#wrapper']['margin-left'] = 0;
	}
	else if($sidebar_l_width) {
		$style['#container']['padding-left'] = ($sidebar_l_width + 40).'px';
		$style['#wrapper']['border-left-width'] = ($sidebar_l_width + 40).'px';
		$style['#wrapper']['margin-left'] = '-'.($sidebar_l_width + 40).'px';
		$style['#sidebar_left'] = array (
			'width' => $sidebar_l_width.'px',
			'margin-left' => '-'.($sidebar_l_width + 40).'px',
		); 
	}	
	if($sidebar_r_fontsize)
		$style['#sidebar_right']['font-size'] = $sidebar_r_fontsize;
	if($sidebar_l_fontsize)
		$style['#sidebar_left']['font-size'] = $sidebar_l_fontsize;
	if($content_fontsize) {
		$style['.postentry p']['font-size'] = $content_fontsize;
		$style['.postentry ul']['font-size'] = $content_fontsize;
		$style['.postentry ol']['font-size'] = $content_fontsize;
	}	
	if($style) {
		echo "\n<!-- Fluid Blue customized styles generated by functions.php -->\n";
		echo "<style type=\"text/css\">\n";
		foreach($style as $selector => $properties) {
			echo $selector." {\n";
			foreach ($properties as $property => $value)
				echo "\t{$property}: {$value};\n";
			echo "}\n";
		}
		echo "</style>\n";
	}
	if($rounded_corners == 'on')
		echo '<link rel="stylesheet" href="'. get_bloginfo('template_url') . '/rounded-corners.css" type="text/css" media="screen" />'."\n";
	if(is_file(get_template_directory().'/custom.css'))
		echo '<link rel="stylesheet" href="'. get_bloginfo('template_url') . '/custom.css" type="text/css" media="screen" />'."\n";
}

add_action('wp_head', 'f2_head');


function f2_admin_head()
{
	if( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) ) {
	$template_url = get_bloginfo('template_url');
?>
<script type="text/javascript" src="<?php echo get_bloginfo('template_url'); ?>/farbtastic/farbtastic.js"></script>
<link rel="stylesheet" href="<?php echo get_bloginfo('template_url'); ?>/farbtastic/farbtastic.css" type="text/css" />

<style type="text/css">
.colorpicker { display:none; }
.colorclose { display:none; }
</style>
<?php
}
}

add_action('admin_head', 'f2_admin_head');

function f2_admin_footer()
{
	if( $_GET['page'] == basename(__FILE__) ) {
?>
<script type="text/javascript">
	jQuery(document).ready(function() {
	if(!jQuery('#f2_sidebar_l').is(':checked')) 
		jQuery('.sidebar_l_dependent').hide();
	jQuery('#f2_sidebar_l').change(function() {
		if(jQuery('#f2_sidebar_l').is(':checked')) 
			jQuery('.sidebar_l_dependent').show();
		else
			jQuery('.sidebar_l_dependent').hide();
	});
	if(!jQuery('#f2_sidebar_r').is(':checked')) 
		jQuery('.sidebar_r_dependent').hide();
	jQuery('#f2_sidebar_r').change(function() {
		if(jQuery('#f2_sidebar_r').is(':checked')) 
			jQuery('.sidebar_r_dependent').show();
		else
			jQuery('.sidebar_r_dependent').hide();
	});
	if(!jQuery('#f2_header_img').is(':checked')) 
		jQuery('.header_img_dependent').hide();
	jQuery('#f2_header_img').change(function() {
		if(jQuery('#f2_header_img').is(':checked')) 
			jQuery('.header_img_dependent').show();
		else
			jQuery('.header_img_dependent').hide();
	});
	if(!jQuery('#f2_hmenu').is(':checked')) 
		jQuery('.hmenu_dependent').hide();
	jQuery('#f2_hmenu').change(function() {
		if(jQuery('#f2_hmenu').is(':checked')) 
			jQuery('.hmenu_dependent').show();
		else
			jQuery('.hmenu_dependent').hide();
	});
	jQuery('#colorpicker-header_bg_color').farbtastic('#f2_header_bg_color');
	jQuery('#colorpicker-header_title_color').farbtastic('#f2_header_title_color');
	jQuery('#colorpicker-header_desc_color').farbtastic('#f2_header_desc_color');
	jQuery('.colorinput').focus(function() {
		if(jQuery(this).val() == '') jQuery(this).val('#');
		jQuery(this).next('.colorclose').show();
		jQuery(this).next('.colorclose').next('div.colorpicker').slideDown();
	});		
	jQuery('.colorclose').click(function() {
		jQuery(this).next('.colorpicker').slideUp();
		jQuery(this).hide();
	});
  });
</script>
<?php
	}
}






add_action('admin_footer', 'f2_admin_footer');


function f2_option($option)
{
	global $shortname, $options;
	return get_option($shortname.'_'.$option, $options[$option]['default']);
}

?>