-1

i have my page in wordpress and i'm trying to include a javascript file for that im using the next code in the footer:

<script src="<?php bloginfo('template_url')?>/js/main.js"></script>

the file it seems is loaded properly but inside that javascript code i call some images.

function sliderimgchange(){

        if ($(window).width() <= 600) {

        var sliderOne  =  $('.slideuno').attr('src', '../images/sliderone-mobile.jpg'),
        sliderTwo  =  $('.slidedos').attr('src', '../images/slidertwo-mobile.jpg'),
        sliderThree  =  $('.slidetres').attr('src', '../images/sliderthree-mobile.jpg');

        } else if ($(window).width() > 600) {

        var sliderOne  =  $('.slideuno').attr('src', '../../images/sliderone.jpg'),
        sliderTwo  =  $('.slidedos').attr('src', '../../images/slidertwo.jpg'),
        sliderThree  =  $('.slidetres').attr('src', '../../images/sliderthree.jpg');
        }
    }

All the images in that javascript file are not loaded when i go to the page. i check the console and the error says that the image is not found. i want to know how to call this scritp so that the images are recognized when i go to the page.

1
  • What is the full "not found" path for those images? Did you check the NET tab in your console?
    – The J
    Commented Feb 28, 2017 at 20:28

1 Answer 1

0

You are missing /wp-content/themes/YOUR_theme_NAME_FOLDER like this:

function sliderimgchange(){

        if ($(window).width() <= 600) {

        var sliderOne  =  $('.slideuno').attr('src', '/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderone-mobile.jpg'),
        sliderTwo  =  $('.slidedos').attr('src', '/wp-content/themes/YOUR_theme_NAME_FOLDER/images/slidertwo-mobile.jpg'),
        sliderThree  =  $('.slidetres').attr('src', '/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderthree-mobile.jpg');

        } else if ($(window).width() > 600) {

        var sliderOne  =  $('.slideuno').attr('src', '/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderone.jpg'),
        sliderTwo  =  $('.slidedos').attr('src', '/wp-content/themes/YOUR_theme_NAME_FOLDER/images/slidertwo.jpg'),
        sliderThree  =  $('.slidetres').attr('src', '/wp-content/themes/YOUR_theme_NAME_FOLDER/images/sliderthree.jpg');
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.