How to Add Javascript Only When a Function Exists?

Hi @Denis Belousov:

Okay, based on your responses I’m going to ask why tie it to the function existing, why not just test the return value of get_option('src_switcher') like this?

function my_scripts() {
  if (!is_admin()) {
    wp_enqueue_script('jquery');
    wp_enqueue_script( 'custom', 
      get_bloginfo('template_directory').'/js/custom.js', 
        array( 'jquery' ), 
        '', 
        true );
    if (is_front_page()) {
      $sliders = get_option('src_switcher'); 
      if ($sliders == 'First slider') 
        wp_enqueue_script( 'jquery1',
          get_bloginfo('template_directory').'/js/jquery.plugin.js', 
          array( 'jquery' ));
      else if ($sliders == 'Second slider') 
        wp_enqueue_script('jquery2',          
          get_bloginfo('template_directory').'/js/jquery.plugin2.js', 
          array( 'jquery' ));
      else if ($sliders == 'Third slider') 
        wp_enqueue_script( 'jquery3',
          get_bloginfo('template_directory').'/js/jquery.plugin3.js', 
          array( 'jquery' )); 
    }
  }
}
add_action('wp_print_scripts', 'my_scripts');

Alternately if you must use the function testing you’ll want the code that defines your functions to look like this:

$sliders = get_option('src_switcher'); 
if ($sliders == 'First slider') 
  function function_one() {
    ...code.. 
  }
else if($sliders == 'Second slider') 
  function function_two() {
    ...code.. 
  }
else if($sliders == 'Third slider') 
  function function_three() {
    ...code.. 
  }

tech