Ready to get started?Download WordPress


[resolved] Using jQuery image gallery with wp (5 posts)

  1. andy.emm
    Posted 1 year ago #

    Hello all-

    I've been trying to get an image slider to work inside of my wordpress, but not sure quite what I'm missing. I've been following the same method I used to get Flexslider to work, but I'm not sure what is going wrong. I've attached the code I'm using in my functions.php file, as well as links to my index.php ( pasetebin ) and the link to the original plugin website. Any help would be greatly appreciated!!

    `function malihu_gallery() {
    if (!is_admin()) {

    // Enqueue Malihu Gallery JavaScript
    wp_register_script('malihu-jquery-image-gallery', get_template_directory_uri(). '/js/malihu-jquery-image-gallery.js', array('jquery'), 1.0, true );

    // Enqueue Malihu Gallery Stylesheet
    wp_register_style( 'malihu-style', get_template_directory_uri() . '/CSS/malihu_gallery.css', 'all' );
    wp_enqueue_style('malihu-style' );

    add_action('wp_footer', 'gallery_settings');


    add_action('init', 'malihu_gallery'); `

    index.php -> http://pastebin.com/hn8JNM4y

    Original plugin site -> http://manos.malihu.gr/simple-jquery-fullscreen-image-gallery

  2. It seems like all you really need to do is enqueue the script/stylesheet, because I'm assuming you have markup in your index.php file. Also, you have an invalid callback on your 'wp_footer' action ... gallery_settings() doesn't exist, at least not in the above example.

    If all you need to do is enqueue the script and stylesheet you can simplify this a bit, something like this: http://pastebin.com/VMRLnHBz

  3. andy.emm
    Posted 1 year ago #

    Hey Drew,

    Thanks so much for the reply. I did get rid of the gallery_settings() (something that I was trying with earlier to fix things) and tried your code. It seems to be registering the CSS and when I check the source, the script is being loaded in the footer. However, for some reason the changes still aren't taking place on the front end. When I check with firebug, it's giving me the error

    TypeError: $ is not a function
    [Break On This Error]


    which is the first line of the javascript code. Would it work to somehow wrap the javascript in a function that wordpress can read?

    Here is a link to the script. -> http://pastebin.com/zALykcCy

    Thanks again for the help!

  4. Would it work to somehow wrap the javascript in a function that wordpress can read?

    From the $ is not a function error, it's possible you just need to add a noconflict wrapper around it. See wp_enqueue_script for more info.

  5. andy.emm
    Posted 1 year ago #

    Thanks Drew!! You're my hero-

    Adding the noconflict wrapper around my code worked perfectly! Amazing--

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.