• Resolved cath_r

    (@cath_r)


    I have created a child theme.
    I want to add some javascript/jquery to the header.

    I created a js file and put that in my child js folder.
    $(document).ready(function(){
    var speed = 3;
    var items, scroller = $(‘#scroller’);
    var width = 0;
    scroller.children().each(function(){
    width += $(this).outerWidth(true);
    });
    scroller.css(‘width’, width);
    scroll();
    function scroll(){
    items = scroller.children();
    var scrollWidth = items.eq(0).outerWidth();
    scroller.animate({‘left’ : 0 – scrollWidth}, scrollWidth * 100 / speed, ‘linear’, changeFirst);
    }
    function changeFirst(){
    scroller.append(items.eq(0).remove()).css(‘left’, 0);
    scroll();
    }
    });

    I included the following lines in the header ( from reading various post on how to do that)

    <script type=”text/javascript” src=”https://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js”></script&gt;
    <script type=”text/javascript” src=”<?get_stylesheet_directory_uri() . ‘/js/cr_ticker.js’;?></script>
    <?php wp_enqueue_script( ‘cr_ticker’ );?>

    However the code is not working. It does if I include it in the header.php
    Can anyone help?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What are the error messages you’ve receiving from JavaScript?
    If you can’t find this out, can you link us the webpage?

    Thread Starter cath_r

    (@cath_r)

    I do not get an error, it just does not run

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    If you’re not receiving an error, try forcing some sort of response from the JavaScript files, like document.write("TEST");, just to see whether the files are loading.

    Thread Starter cath_r

    (@cath_r)

    THanks for the suggestion . nothing happens

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you link the web page with the error?

    Thread Starter cath_r

    (@cath_r)

    Thanks
    I can see in the source if it not finding the file

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Have you concluded whether the JavaScript files are loading?

    Thread Starter cath_r

    (@cath_r)

    yes, it is not loading because it is not finding it

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    In which directory are your JavaScript files?

    Thread Starter cath_r

    (@cath_r)

    well I had a syntax error to start with
    but i found that the styelsheet directory refers to another directory where the same theme was installed initally. ( i am doing that for a friend and I had to do a new install of wordpress because he had done something wrong.
    but somehow, the stylesheet directory refers to the old one

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Are your JavaScript files in this directory;

    /wp-content/themes/yourTheme/js/

    I don’t think you need to use the stylesheet directory function.

    Thread Starter cath_r

    (@cath_r)

    ok ??

    Thread Starter cath_r

    (@cath_r)

    ah thanks for the help ?? ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘jquery/javascript modification to header.php’ is closed to new replies.