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

JavaScript

Konrad Pilch
Konrad Pilch
2,435 Points

Please help me to solve these JS loading problem

Heres the website im trying to debug from JS errors. It doesn't load it or make anything. Or it does load but it doesn't work. What can i do? i saw that there was some JS problem or jQuery from the contact form 7 in script.js which I believe its their fault? and its not even sending me a message when i submit even tho everything is saying i submitted.

Im using WordPress for this site. I have developed that theme, and JS is dead.

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

The first thing to try is to make sure you're removing version numbers from your CSS links. If you view the source you can see them showing up.

Try adding somethng like this into your functions.php file

function remove_cssjs_ver( $src ) {
    if( strpos( $src, '?ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );

Also remember jQuery is included with Wordress so you may need to remove any hard coded links to jquery.

Good luck.

Konrad Pilch
Konrad Pilch
2,435 Points

It has no effect.

These are my functions

function theme_styles() {

    wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css');
    wp_enqueue_style( 'style_css', get_template_directory_uri() . '/style.css');
}
add_action( 'wp_enqueue_scripts', 'theme_styles' );

function theme_js() {

    global $wp_scripts;

    wp_register_script( 'html5_shiv', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', '', '', false );
    wp_register_script( 'respond_js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', '', '', false );


    $wp_scripts->add_data( 'html5_shiv', 'conditional', 'lt IE 9' );
    $wp_scripts->add_data( 'respond_js', 'conditional', 'lt IE 9' );

    wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/main.js', array('jquery'), '', true );
    wp_enqueue_script( 'js_js', get_template_directory_uri() . '/js/js.js', array('jquery'), '', true );


}
add_action( 'wp_enqueue_scripts', 'theme_js');



function my_init() {

        wp_deregister_script('jquery');

        // load the local copy of jQuery in the footer
        wp_register_script('jquery', 'js/jquery.js', false, '2.11.1', true);

        // or load the Google API copy in the footer
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.11.1/jquery.min.js', false, '2.11.1', true);

        wp_enqueue_script( 'jquery_js', get_template_directory_uri() . 'js/jquery.js', array('jquery'), '', true );

}
add_action('init', 'my_init');



// Font Awesome
add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' );

function enqueue_font_awesome() {

    wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css' );

}

Obeviously i don thave any hardcoded code xd all dynamically with functions.

Can you explain what are you trying to do here?

function my_init() {

        wp_deregister_script('jquery');

        // load the local copy of jQuery in the footer
        wp_register_script('jquery', 'js/jquery.js', false, '2.11.1', true);

        // or load the Google API copy in the footer
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.11.1/jquery.min.js', false, '2.11.1', true);

        wp_enqueue_script( 'jquery_js', get_template_directory_uri() . 'js/jquery.js', array('jquery'), '', true );

}
add_action('init', 'my_init');

remove this hook completely see if that fixes it

Konrad Pilch
Konrad Pilch
2,435 Points

oh , xd i fixed that, thank you for your answer, i will have look a this as wlell.

But what im on about, is how do i make a parallax effect on my blog pagE? because when i do it, the image goes straight top and will never see it again.