• Hi. Does anyone know if there is any advantage to creating a child theme, or to instead use a wordpress plugin that allows you to apply style and javascript to your existing theme in the word press dashboard?

    For example I am using the free responsive theme, and I created a child theme for that. But I noticed it has the build in capability to allow a stylesheet to be applied to it, and also for JavaScript to be inserted in the header and or footer.

    However I have found that with the child theme, when I applied a custom JS file, it seemed like the libraries were not being included as I kept getting errors in the dev console no matter how simple of code I tried (console.log worked). I tried the same thing in the build in JS plugin and got the same errors, but that could be because of my functions.php file in my child theme screwing things up. Maybe if I just deleated the child theme, used the built in stylesheet, then the build in JS would have access to the library.

    Thoughts?

Viewing 7 replies - 1 through 7 (of 7 total)
  • As far as I am concerned, it’s not so much a question of ‘either / or’, but a matter of applying what works under the circumstances you’re in.

    A childtheme has several ‘roles’ to play:

    • it separates the changes YOU make, from the original theme. This makes it easier to control the ‘look and feel’ of your site
    • it will ensure that any updates by the author of the theme will NOT overwrite the changes / adaptations you made (a major update of the parent theme MAY require changes to the childtheme).In most cases, updates won’t cause problems

    When applying JS / making changes, things may get a bit more complicated. On occasion it may require you to make THESE js-changes the parent [unfortunately].

    Alternatively, you could use a plugin like ‘SuperSlider-Perpost-Code’; It allows you to add JS and CSS to individual posts as required.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    However I have found that with the child theme, when I applied a custom JS file, it seemed like the libraries were not being included as I kept getting errors in the dev console no matter how simple of code I tried (console.log worked).

    Did you narrow this down and find out what the issue was? Link the site with the issue if you’re unsure.

    Thread Starter Adrian Houle

    (@adrian-houle)

    Thanks Ginfo, cleared things up a bit for me.

    And no I spent hours and hours trying to figure out the problem, eventually gave up and changed the html in the parent theme instead; but that has been bugging me cause I know its bad practice.

    Here is the page: http://adrianhoulewebprojects.com/JacquesHoule/

    I added a jquery function so you can see the error in the dev console.
    I added ( ".textLinkHybrid" ).remove(); because i was originally trying to remove the copyright link and replace it with a credit link (.textLinkHybrid used to be a class called copyright but I changed that when I changed the html so that my CSS reffernce made sense). I know what I just did does not accomplish the replacement, as I need to use a replace child function, but I get the same kind of error no matter what function I use, just with the class name and functionchanged to whatever I used.

    Its always Object xxx has no methodYYY`
    The denying of load errors have always been there and I am not overly concerned about them as my website functions fine.

    Thread Starter Adrian Houle

    (@adrian-houle)

    And to prove this, responsive theme just updated and the footer is back to the way it was.

    So any ideas on how to get the JS working?

    ?? Have you tried integrating the JS now the theme has been updated??
    Perhaps the update corrected this glitch??

    [make a back-up first!!]

    Thread Starter Adrian Houle

    (@adrian-houle)

    Still does not work. Ill include the code I am using in my functions.php file, it’s straight from the instructions. The part that confuses me is the comments say “register your script location, dependencies and version” but I see nothing including the dependencies. However reading this article: http://msyk.es/blog/prevent-jquery-wordpress-theme/ I am not supposed to included any libraries here anyways, and it is best if I use a plugin to ensure the libraries are included. Did that but it does not help.
    The only thing i have not tried is deleating my functions.php file and just writing the JS in the build in JS fields in the dashboard. But even if that worked it would not be my goal to make an independent child theme.
    The real weird thing is, I get an error if I use the $ symbol for variables, and that is because wordpresses version of the libraries do not use that, but if taking that away fixes one of the errors, then that must mean that I am accessing the library. Have just every bit of javascript I have tried out, no matter how simple, just been wrong? I am tearing out my beard hair over this!

    <?php
    
    /*included custom javascript from child theme*/
    if ( !is_admin() ) { // instruction to only load if it is not the admin area
       // register your script location, dependencies and version
       wp_register_script('custom_script',
           get_bloginfo('stylesheet_directory') . '/js/custom_script.js',
           array('jquery'),
           '1.0' );
    
       // enqueue the script
       wp_enqueue_script('custom_script');
    }
    
    ?>
    Thread Starter Adrian Houle

    (@adrian-houle)

    My last resort for this is to try and get a php script working in my child theme that does what I want to do. This may actualy be better practice sense javascript can be turned off and php cannot. But I still want to get JS and Jquery working for the day I need to use it for something php cannot do.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘child theme vs plugin CSS and JS editor’ is closed to new replies.