.js files

This topic is: not resolved

This topic contains 6 replies, has 3 voices, and was last updated by  manavecplan 2 years, 1 month ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #12422

    manavecplan
    Participant

    Hey,

    I’m a brand spanking new user of Genesis(waves to GaryJ) and I had a couple of queries on loading .js scripts

    A)Physically, which folder are .js scripts stored in under Genesis?

    B) How do you guys actually load the scripts? Is there a field I need to paste the script locations into? Or is it that enqueue_script thing in custom php?

    The questions may seem a bit simplistic but I’m coming over from Thesis and .js is handled a bit different over there.

    #12430

    SoZo
    Moderator

    In Genesis they are in lib=>js

    Genesis provides header and footer script boxes in its settings panel. Otherwise you can load them through functions.php using enqeue_script.


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

    #12580

    manavecplan
    Participant

    Thanks so much John!

    Would the following be a valid example of using the enqueue script?

    <code>

    function ronald_load_scripts() {
    if ( ! is_admin() ) {
    wp_register_script( ‘zoomPercent’, get_template_directory_uri() . ‘/js/zoom.js’, array( ‘jquery’ ) );
    wp_register_script( ‘infiniteCarousel’, get_template_directory_uri() . ‘/js/cursoule.js’, array( ‘jquery’ ) );

    wp_enqueue_script( ‘zoomPercent’ );
    wp_enqueue_script( ‘infiniteCarousel’ );
    }
    }
    add_action( ‘wp_enqueue_scripts’, ‘ronald_load_scripts’ );</code>

    #12633

    SoZo
    Moderator

    Yes, that’s it if you don’t want it loading for admins


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

    #12734

    manavecplan
    Participant

    Almost there, John.

    This is my current code:

    function load_scripts() {
    wp_register_script('fokus', get_template_directory_uri(). '/js/fokus.js');
    wp_enqueue_script('fokus');
    }
    add_action('wp_enqueue_scripts', 'load_scripts');

    However, it refuses to load from the js folder in my child theme. What am I doing wrong here?

    My site is: http://cityslick.in/ and the js is from https://github.com/hakimel/Fokus

    #12748

    Jen Baumann
    Keymaster

    You need this for a child theme: http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri :) Right now you’re code is looking in the parent theme.


    If you need technical support for your theme please file a ticket.

    The forums are community based. Staff only monitors the forum for issues relating to the forum itself and to redirect users to where they need to go.

    #12872

    manavecplan
    Participant

    Thanks Jen!

    My new code is as follows:


    function load_scripts() {
    wp_register_script('fokus', get_stylesheet_directory_uri(). '/js/fokus.js');
    wp_enqueue_script('fokus');
    }
    add_action('wp_enqueue_scripts', 'load_scripts');

    I don’t see where I’m going wrong…now everything seems to be correct and it’s still not being loaded as per my page source. And it’s apparently childishly simple according to the example by the js dev…

    Still no cigar… :-(

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.