Support » Fixing WordPress » Parent Theme JS Issue – 404 File Not Found

  • I recently built a site using the Mk theme. I’ve been editing it quite a bit and ultimately decided that I needed to create a child theme. I’ve never done that before, so I looked up and followed instructions – created a style.css file and a functions.php file. I moved my custom styles from my custom css plugin to the new stylesheet, enqueued my parent theme’s css in the functions.php. That’s all working fine.

    However, I’m getting a load of 404 File Not Found errors for my parent theme’s JS. No instructions said anything about enqueuing the parent theme’s JS. I looked around and, for the most part, all I found were topics about adding your own custom JS. I’m not adding custom JS, I just want the existing JS to load properly. I found one topic suggesting to include the enqueueing for the JS anyway and another suggesting just copying the JS files to the child theme (which seems like it defeats the purpose of a child theme). I tried both and it didn’t work.

    Do I have to copy the JS files? Do I have to enqueue the JS from the parent theme? If so, is there just something wrong with my enqueue scripts below? I appreciate any help!

    Here is my current functions.php text.

    <?php
    add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
    function enqueue_child_theme_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
        wp_enqueue_style( 'editor-style', get_template_directory_uri() . '/editor-style.css' );
        wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css' );
        wp_enqueue_style( 'jquery', get_template_directory_uri() . '/css/jquery.mCustomScrollbar.min.css' );
        wp_enqueue_style( 'mk', get_template_directory_uri() . '/css/mk.css' );
        wp_enqueue_style( 'mk-fontawesome', get_template_directory_uri() . '/fonts/font-awesome/css/font-awesome.css' );
        wp_enqueue_style( 'mk-zocial', get_template_directory_uri() . '/fonts/zocial/zocial.css' );
        wp_enqueue_style( 'mk-pixons', get_template_directory_uri() . '/fonts/pixons/pixons.css' );
        wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/css/custom-style.css' );
        wp_enqueue_style( 'content-sidebar', get_template_directory_uri() . '/layouts/content-sidebar.css' );
        wp_enqueue_style( 'mk', get_template_directory_uri() . '/layouts/sidebar-content.css' );
        wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('parent-style')  );
        wp_enqueue_script( 'mk-superslides', get_template_directory_uri() .'/js/jquery.superslides.js',array('jquery'), $theme_name, null, true );
    	wp_enqueue_script( 'mk-home-slider-init', get_template_directory_uri() . '/js/mk-home-slider-init.js', array( 'jquery' ), '1.0',true );
    	wp_enqueue_script( 'mk-metisMenu', get_template_directory_uri() .'/js/metisMenu.js',array('jquery'), $theme_name, null, true );
    	wp_enqueue_script( 'mk-bootstrap-js', get_template_directory_uri() .'/js/bootstrap.js',array('jquery'), $theme_name, null, true );
    	wp_enqueue_script( 'mk-cycle-js', get_template_directory_uri() .'/js/jquery.cycle2.js',array('jquery'), $theme_name, null, true );
    	wp_enqueue_script( 'mk-init', get_template_directory_uri() .'/js/mk-init.js', false,array('jquery'),$theme_name, null, true );
    	wp_enqueue_script( 'mk-navigation', get_template_directory_uri() . '/js/navigation.js', array(), $theme_name, true );
    	wp_enqueue_script( 'mk-custom-scrollbars', get_template_directory_uri() . '/js/jquery.mCustomScrollbar.concat.min.js', array(), $theme_name, true );
    	wp_enqueue_script( 'mk-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js',array('jquery'), $theme_name, true );
    }

    Here is a copy of the error messages though I linked to the site at the top:
    GET http://poetic-logic.com/wp-content/themes/mk/css/custom-style.css?189db0 404 (Not Found)
    jquery-migrate.min.js?189db0:2 JQMIGRATE: Migrate is installed, version 1.4.0
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/navigation.js%20Child-1.0.0?189db0
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/jquery.cycle2.js%20Child-1.0.0?189db0
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/jquery.superslides.js%20Child-1.0.0?189db0
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/metisMenu.js%20Child-1.0.0?189db0
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/bootstrap.js%20Child-1.0.0?189db0 404 (Not Found)
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/skip-link-focus-fix.js%20Child-1.0.0?189db0
    (index):183 GET http://poetic-logic.com/wp-content/themes/mk/js/jquery.mCustomScrollbar.concat.min.js%20Child-1.0.0?189db0 404 (Not Found)
    mk-home-slider-init.js?189db0:3 Uncaught TypeError: jQuery(…).superslides is not a function(anonymous function) @ mk-home-slider-init.js?189db0:3i @ jquery.js?189db0:2j.fireWith @ jquery.js?189db0:2n.extend.ready @ jquery.js?189db0:2K @ jquery.js?189db0:2
    mk-init.js?ver[0]=jquery&189db0:40 Uncaught TypeError: $(…).mCustomScrollbar is not a function(anonymous function) @ mk-init.js?ver[0]=jquery&189db0:40n.event.dispatch @ jquery.js?189db0:3r.handle @ jquery.js?189db0:3

Viewing 4 replies - 1 through 4 (of 4 total)
  • Can you share the code from the parent theme where it’s enqueueing the Javascript?

    Thx.

    Thread Starter continuumcomplex

    (@continuumcomplex)

    Certainly, here it is from the parent theme’s functions.php

    I went ahead and copied the whole file incase there was more in there that might be needed.

    [code moderated - follow the forum guidelines for posting code - http://codex.wordpress.org/Forum_Welcome#Posting_Code - and use the http://pastebin.com/%5D

    Hi,

    So I spotted a couple of problems with the code you shared. The first is that some of the calls to wp_enqueue_script are being passed an incorrect number of parameters. This function takes at most 5 parameters, but some are being passed 6. For example:

    wp_enqueue_script( 'mk-superslides', get_template_directory_uri() .'/js/jquery.superslides.js',array('jquery'), $theme_name, null, true );

    In the above code, the null should be removed since it doesn’t match up with what wp_enqueue_script expects. You’ll need to go through each one and enqueue these scripts properly in your child theme in order to override the erroneous enqueuing by the parent theme.

    The other thing I noticed is that the URLs that aren’t accessible all have a % in it. That should actually be a ?. You can confirm by pasting the URL into your browser and replacing %20 with ?.

    This suggests an encoding issue with the $theme_name variable, and I believe it’s because your child theme’s name is “MK Child”. The space is likely what’s messing things up. Indeed, all of the files that are failing to load are using the $theme_name variable.

    In order to resolve this second issue, I would suggest replacing $theme_name variable with $lnt_version instead, which is the theme’s version. There’s really no need to include the theme’s name as part of the version anyway.

    Hope that helps.

    Thread Starter continuumcomplex

    (@continuumcomplex)

    Thank you for your help. I tried making the recommended changes but apparently I’m doing something wrong, I’m still getting the same errors. The child theme name was mk-child, which I thought would be fine, but I removed the dash and changed it to mkchild. I also changed the $theme_name references in the child theme functions.php to $lnt_version as I added the script enqueueing from the parent theme into the child theme functions.php and removed null.

    Here is my current functions.php file.

    <?php
    add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
    function enqueue_child_theme_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
        wp_enqueue_style( 'editor-style', get_template_directory_uri() . '/editor-style.css' );
        wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css' );
        wp_enqueue_style( 'jquery', get_template_directory_uri() . '/css/jquery.mCustomScrollbar.min.css' );
        wp_enqueue_style( 'mk', get_template_directory_uri() . '/css/mk.css' );
        wp_enqueue_style( 'mk-fontawesome', get_template_directory_uri() . '/fonts/font-awesome/css/font-awesome.css' );
        wp_enqueue_style( 'mk-zocial', get_template_directory_uri() . '/fonts/zocial/zocial.css' );
        wp_enqueue_style( 'mk-pixons', get_template_directory_uri() . '/fonts/pixons/pixons.css' );
        wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/css/custom-style.css' );
        wp_enqueue_style( 'content-sidebar', get_template_directory_uri() . '/layouts/content-sidebar.css' );
        wp_enqueue_style( 'mk', get_template_directory_uri() . '/layouts/sidebar-content.css' );
        wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('parent-style')  );
    if(is_home() || is_front_page()):
    wp_enqueue_script( 'mk-superslides', get_template_directory_uri() .'/js/jquery.superslides.js',array('jquery'), $lnt_version, true );
    wp_enqueue_script( 'mk-home-slider-init', get_template_directory_uri() . '/js/mk-home-slider-init.js', array( 'jquery' ), '1.0',true );
    wp_localize_script( 'mk-home-slider-init', 'homeSLIDER', array(
    'slideSPEED' => get_theme_mod('mk_slide_speed','5000')
    ) );
    
    endif;
        wp_enqueue_script( 'mk-metisMenu', get_template_directory_uri() .'/js/metisMenu.js',array('jquery'), $lnt_version, true );
        wp_enqueue_script( 'mk-bootstrap-js', get_template_directory_uri() .'/js/bootstrap.js',array('jquery'), $lnt_version, true );
        wp_enqueue_script( 'mk-cycle-js', get_template_directory_uri() .'/js/jquery.cycle2.js',array('jquery'), $lnt_version, true );
        wp_enqueue_script( 'mk-init', get_template_directory_uri() .'/js/mk-init.js', false,array('jquery'),$lnt_version, true );
        wp_enqueue_script( 'mk-navigation', get_template_directory_uri() . '/js/navigation.js', array(), $lnt_version, true );
        wp_enqueue_script( 'mk-custom-scrollbars', get_template_directory_uri() . '/js/jquery.mCustomScrollbar.concat.min.js', array(), $lnt_version, true );
        wp_enqueue_script( 'mk-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js',array('jquery'), $lnt_version, true );
        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    wp_enqueue_script( 'comment-reply' );
    }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Parent Theme JS Issue – 404 File Not Found’ is closed to new replies.