Community Forums › Forums › Archived Forums › General Discussion › .js files
- This topic has 6 replies, 3 voices, and was last updated 12 years, 9 months ago by
manavecplan.
-
AuthorPosts
-
January 16, 2013 at 3:20 pm #12422
manavecplan
MemberHey,
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.
January 16, 2013 at 3:26 pm #12430SoZo
MemberIn 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
January 17, 2013 at 2:14 am #12580manavecplan
MemberThanks 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>January 17, 2013 at 10:32 am #12633SoZo
MemberYes, that's it if you don't want it loading for admins
John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography
January 17, 2013 at 4:00 pm #12734manavecplan
MemberAlmost 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
January 17, 2013 at 5:32 pm #12748Jen Baumann
ParticipantYou 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.
January 18, 2013 at 10:25 am #12872manavecplan
MemberThanks 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... 🙁
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.