I have a few function. For both of them need javascript code. I need to add javascript code in header only when function is active. At this time I have all my javascript code in header for all my function and newermind which one of them is active. I tried to make this code but nothing is changed: All I have in scripts.php
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()) {
if (function_exists('function_one'))
wp_enqueue_script( 'jquery1',
get_bloginfo('template_directory').'/js/jquery.plugin.js',
array( 'jquery' ));
else if (function_exists('function_two'))
wp_enqueue_script('jquery2',
get_bloginfo('template_directory').'/js/jquery.plugin2.js',
array( 'jquery' ));
else if (function_exists('function_three'))
wp_enqueue_script( 'jquery3',
get_bloginfo('template_directory').'/js/jquery.plugin3.js',
array( 'jquery' ));
}
}
}
add_action('wp_print_scripts', 'my_scripts');
mycode.php This code include all my three functions. Looks like:
function function_one() { ?>
...code..
<?php }
function function_two() { ?>
...code..
<?php }
function function_three() { ?>
...code..
<?php }
This two files are defined in functions.php.
I'm new in php, please help me how should I need to do? Thank you!
UPDATE
Function for choosing slider's looks like this
function sliders {
$sliders = get_option('src_switcher'); // array in theme options with sliders name
if($sliders == 'First slider') {
function_one();
}
if($sliders == 'Second slider') {
function_two();
}
if($sliders == 'Third slider') {
function_three();
}
}
function_exists (). (You did way you were new to PHP, right? Sometimes we ask questions because we know PHP and thus know we need to ask. :)function_exists()calls will always return true. Can you update your example to explain your use-case instead of using abstract names like'function_one'so I can understand what you are actually trying to do? (Often people ask the wrong question and understanding your goal helps us understand how to answer.)