Chonchol Mahmud
Chonchol Mahmud

Reputation: 2735

How can I load custom jQuery in header of WordPress?

I have a website in WordPress. It's have a site preloader (Queryloader2). But when I go to my site its load first site after then loader. But it should load loader first. If I add it in header part then it works well. I am adding in header below this coded:

See the site here (now queryloader added in footer)

<head>
    <?php wp_head(); ?>
    <script type="text/javascript" src="<?php bloginfo("template_directory"); ?>/js/jqueryloader2.min.js"></script>  
</head>

But when I click on any image then its blank with black color.

Now my code for this site is:

functions.php: (just one functions part)

if (is_home() || is_archive()) {
    wp_enqueue_script( 'sliphover', get_template_directory_uri() . '/js/jquery.sliphover.min.js', array ( 'jquery' ), null , true);
    wp_enqueue_script( 'queryloader2', get_template_directory_uri() . '/js/queryloader2.min.js', array ( 'jquery' ), null , true);
}elseif (is_single()) {
    wp_enqueue_style('fancy-box',  get_template_directory_uri() . '/css/jquery.fancybox.css', '');
    wp_enqueue_script( 'fancybox', get_template_directory_uri() . '/js/jquery.fancybox.js', array ( 'jquery' ), null , true);
    wp_enqueue_script( 'easing', get_template_directory_uri() . '/js/jquery.easing.1.3.js', array ( 'jquery' ), null , true);

My one question is: how can add custom jQuery in header of WordPress site? And it just for a specific page (home).

Thanks in advance.

Upvotes: 1

Views: 153

Answers (1)

vrajesh
vrajesh

Reputation: 2942

Try This :
Replace false with true. So js file will add in head.

if (is_home() || is_archive()) {
    wp_enqueue_script( 'sliphover', get_template_directory_uri() . '/js/jquery.sliphover.min.js', array ( 'jquery' ), null , false);
    wp_enqueue_script( 'queryloader2', get_template_directory_uri() . '/js/queryloader2.min.js', array ( 'jquery' ), null , false);
}elseif (is_single()) {
    wp_enqueue_style('fancy-box',  get_template_directory_uri() . '/css/jquery.fancybox.css', '');
    wp_enqueue_script( 'fancybox', get_template_directory_uri() . '/js/jquery.fancybox.js', array ( 'jquery' ), null , false);
    wp_enqueue_script( 'easing', get_template_directory_uri() . '/js/jquery.easing.1.3.js', array ( 'jquery' ), null , false);

Upvotes: 1

Related Questions