Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1153557
    alriteam
    Participant

    Hello,

    Please help me with adding js files. I have a js file which I duplicated and wants to add both the files.

    Below is what I tried in function.php of child theme.

    function child_scripts() {
    wp_enqueue_script(‘main’,get_stylesheet_directory_uri().’/main.js’, array( ‘jquery’ ), null, false);
    wp_enqueue_script(‘main1′,get_stylesheet_directory_uri().’/main1.js’, array( ‘jquery’ ), null, false);
    }

    Wordpress – 4.5.3
    X theme – 4.6.1
    Cornerstone – 1.3

    Thanks in advance.

    #1153580
    CMNerds
    Participant

    This may be a silly question but did you create a folder for your custom js file in your child theme folder? If so, don’t forget to use that in your code (for example if you created a js folder then be sure to use js/main.js)

    Give this a shot in your functions.php and let me know if it works.

    function custom_scripts() {
    
    wp_register_script( 'custom-script', get_stylesheet_directory_uri() . 'YOUR-FILE-PATH-HERE.js', array() , false, true );
    
    wp_enqueue_script( 'custom-script' );
    
    }
    
    add_action( 'wp_enqueue_scripts', 'custom_scripts', 99 );
    #1153590
    CMNerds
    Participant

    One more thing, I’m not sure if you started your functions.php in the child theme folder from scratch but make sure you are formatting your php file correctly:

    <?php
    
    /* custom PHP functions start here */
    
    ?>
    #1153605
    alriteam
    Participant
    This reply has been marked as private.
    #1153619
    Christian
    Moderator

    Please see http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/ to learn how to properly add scripts in WordPress.

    Thanks.

  • <script> jQuery(function($){ $("#no-reply-1153557 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>