Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: My JS files are not executing any of their code, nor do they return a 404 error

Here's my jQuery code:

jQuery(document).ready(function() {
    var $window = jQuery(window);

    console.log("Pre-page height: " + $window.height());
    jQuery('.main-content .home-block').height($window.height());

    $window.on('resize', function(){
        console.log("Resize event height: " + $window.height());
        jQuery('.main-content .home-block').height($window.height());
    });
});

This is my current <head> code:

  <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <title><?php cs_wp_title(); ?></title>
    <?php if( ! cs_get_option( 'non_responsive' ) ) { ?>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <?php } else { ?>
    <meta name="viewport" content="width=1200">
    <?php } ?>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.js" />
    <!-- Start of imported scripts -->
    <script type="text/javascript" src="/js/customjs/main.js" />
    <script type="text/javascript" src="/js/panelsnap/jquery.panelsnap.js" />
    <!-- End of imported scripts -->
    <link rel="profile" href="http://gmpg.org/xfn/11" />
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    <?php if ( is_search() || is_404() ) { echo '<meta name="robots" content="noindex, nofollow" />'; } ?>
    <?php if ( cs_get_option( 'favicon' ) ) { echo '<link rel="shortcut icon" href="'. cs_get_option( 'favicon' ) .'" />'; } ?>
    <?php wp_head(); ?>
  </head>

My console is clean, and there is no error visible. Nothing strange is happening on my page as well. What's the problem here?

like image 228
Rizky Fakkel Avatar asked Dec 06 '25 02:12

Rizky Fakkel


1 Answers

Alright, here's a lesson well learned:

Always check your jQuery CDN.

It wasn't working. A normal console.log or alert gave me a response, but anything with a jQuery selector would derp out.

I switched from the jQuery CDN:

<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.js" />

To the Google CDN

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

And it started working.

like image 67
Rizky Fakkel Avatar answered Dec 08 '25 15:12

Rizky Fakkel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!