• I have created a small jquery function which I have placed in a general.js file inside the child theme folder, and have used enque in the functions.php file but I still cant get it to work.

    This is inside functions.php

    function my_assets() {
    	wp_enqueue_script( 'parent', get_stylesheet_directory_uri() . 'https://www.mysite.co.uk/little-stove-company/wp-content/themes/twentytwenty-child/js/general.js', array( 'jquery' ) );
    }

    Then inside my general.js file I have this

    jQuery(document).ready(function( $ ) {	
    	$('.post-85.modula-items.img.pic').each( function() {
        var $img = $(this),
            href = $img.attr('/newpage');
        $img.wrap('<a href="' + href + '" class="link"></a>');
    	});	
    });

    Then when I look in console on the page above I get this issue.
    Loading failed for the <script> with source “https://www.mysite.co.uk/little-stove-company/wp-content…wp-content/themes/twentytwenty-child/js/general.js?ver=5.3.2”.

    Im noty sure what is broken and why its not working.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    should be

    wp_enqueue_script( 'parent', get_stylesheet_directory_uri() . '/js/general.js', array( 'jquery' ) );

    assuming that js is a subdirectory of your child theme.

    Thread Starter accend4web

    (@accend4web)

    Ah cool, yes the error has gone now. Just have to work out why the rest of my script isnt working now.

    Thank you

    Just so it’s clear: using get_stylesheet_directory_uri() will give you the child theme directory. So your script handle probably shouldn’t be ‘parent’.

    And in your script, what are you trying to do with href = $img.attr('/newpage');? Attribute names can’t have slashes.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using wp_enqueue_script to use Jquery’ is closed to new replies.