Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Getting Internal Server Error When Including JavaScript

Hello, whenever I include JavaScript via the functions.php file, I keep getting an Internal Server Error. Whenever I take out the JavaScript, my site works fine (without JavaScript, of course, which is an issue).

My functions.php file looks like this:

<?php

function wpt_theme_styles() {

    wp_enqueue_style( 'normalize', get_template_directory_uri() . '/css/normalize.css' );
    wp_enqueue_style( 'grid', get_template_directory_uri() . '/css/grid.css' );
    wp_enqueue_style( 'headerstyle', get_template_directory_uri() . '/css/headerstyle.css' );
    wp_enqueue_style( 'headerstyleie', get_template_directory_uri() . '/css/headerstyleie.css' );
    wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
}


add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );


function wpt_theme_js() {

    wp_enqueue_scripts( 'responsive-nav', get_template_directory_uri() . '/js/responsive-nav.js', '', '', false );
    wp_enqueue_scripts( 'jquery-isotopemin', get_template_directory_uri() . '/js/jquery.isotope.min.js', 'array(jquery)', '', false );
    wp_enqueue_scripts( 'fastclick', get_template_directory_uri() . '/js/fastclick.js', '', '', true );
    wp_enqueue_scripts( 'scroll', get_template_directory_uri() . '/js/scroll.js', '', '', true );
    wp_enqueue_scripts( 'fixed-responsivenav', get_template_directory_uri() . '/js/fixed-responsive-nav.js', '', '', true );
    wp_enqueue_scripts( 'app', get_template_directory_uri() . '/js/app.js', 'array(jquery)', '', true );

}

add_action ( 'wp_enqueue_scripts', 'wpt_theme_js' );
?>

I noticed that it is particularly happening when I include the wp_head tag in my header.php:

<!DOCTYPE html>
<html>

<head>
<title><?php wp_title(); ?></title>

<?php wp_head(); ?>

</head>

<body>

<!--Logo and Navigation -->

<div id="header">
    <header>
      <a href="index.html" class="logo" data-scroll>Test</a>

      <nav class="nav-collapse">
        <ul>
          <li class="menu-item"><a href="about.html" data-scroll>About</a></li>
          <li class="menu-item"><a href="portfolio.html" data-scroll>Portfolio</a></li>
          <li class="menu-item"><a href="blog.html" data-scroll>Blog</a></li>
          <li class="menu-item"><a href="contact.html" data-scroll>Contact</a></li>
        </ul>
      </nav>
    </header>
</div>

One thing I notice is that the error happens even if I include just one of the enqueue scripts. As soon as the first one is down, the site falls into error.

The URL of my website is here: http://rrzart.com/

Am I missing something here? Thanks for any help given, I'm really lost here!

Edit - I reinstalled Wordpress completely and still am having the issue. So I'm now really lost as to what to do.

2 Answers

Ricardo,

You're close, but you're not properly registering and enqueuing the script(s). Here's an excellent article that does a great job of explaining what I mean: http://wpcandy.com/teaches/how-to-load-scripts-in-wordpress-themes

Especially notice how scripts are registered. I highly recommend that you read that article and try to understand it yourself, rather than copy-and-pasting code that someone posts here. Learning how to enqueue scripts is crucial for leveling up with WP.

Hope this helps.

Thank you so much! This fixed the issue right up and I definitely read the article thoroughly. I have another issue, but I'll make a new thread to cover that issue. Thanks!