Forums

A simple attempts to load a js file (3 posts)

  1. johnbroometwo
    Member
    Posted 1 year ago #

    Hi All,

    I am trying to get icarousel.js to tun with thesis 1.8 but it will not.

    Here is the php to try and get it:-
    This is located in custom_functions.php that thesis uses for all pages.

    /* icarosel added js and css  */
    function add_icarousel (){
    wp_enqueue_script('icarouseljs','http://www.tmvillage.org.uk/wp-content/themes/thesis_18/custom/icarousel.js');
    }
    add_action('thesis_hook_before_content_area', 'add_icarousel');
    
    /* icarosel added js and css  */

    Anyone got any ideas?

    Cheers,

    John

  2. Mark / t31os
    Moderator
    Posted 1 year ago #

    Your action likely runs too late for the enqueue to work..

    add_action('thesis_hook_before_content_area', 'add_icarousel');

    Enqueues typically run in the head of a document, a hook for content will be too late in the process to properly make the enqueue..

    Or at least that would be my guess..

    The thesis members forum will probably be able to better advise you on a suitable hook for your enqueue (i don't personally know the Thesis code to advise on one).

  3. UlukaiThemeDesign
    Member
    Posted 1 year ago #

    Code:

    // LOAD SCRIPTS
    function mytheme_init_js() {
    	wp_register_script( 'icarouseljs', get_bloginfo( 'template_directory' ).'/custom/icarousel.js', null, null, true );
    }
    add_action( 'init', 'mytheme_init_js' );

    This will load your scripts using the wp_footer hook (usually located right before the closing body tag), which is considered a good practice.

    If a script needs to be called before the content has loaded, i.e. in the header (such as the HTML5 enabler script), simply change the true at the end of its corresponding wp_register_script to a false.

Topic Closed

This topic has been closed to new replies.

About this Topic