Working Code Status:
I was testing my js files, what these files were adding and running correctly or not. So I write a alert code in my-custom.js with my theme functionality, and now I hook my jquery file path with in a function. and I hook it by this hook code. add_action('init', 'run_jquery');
My following code work and it displays alert message & also run my functionalists, which are written on my-custom.js file.
function run_jquery()
{
// I used this for assurity of function is running or not.
echo "<h1>Inside Function</h1>";
if (!is_admin())
{
// I used this for assurity of condition is working or not.
echo "<h1>Inside Admin condition</h1>";
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js', true, '1.8.1');
wp_register_script( 'my-custom-js', get_template_directory_uri() . '/js/my-custom.js', array( 'jquery' ), true );
wp_enqueue_script('jquery');
wp_enqueue_script('my-custom-js');
}
}
add_action('init', 'run_jquery');
Problem Facing:
But when I want to hook this function by this way, add_action('wp_enqueue_script', 'run_jquery');
and want to display in footer by this do_action('wp_enqueue_script');
it only shows alert message from my-custom.js file, but not echo values inside function run_jquery() and nor run functionality which is in my-custom.js file, while only get alert("hello world") message from my-custom.js file without going inside function run_jquery(). I did not understand how this piece of code run without going inside of run_jquery() function.