• I have been trying to link a local javascript file to my website for quite some time and I can’t get it to work. I have tried every option I have found online and none of them work for me. I also have a local css file that seems to work fine even when I don’t have it linked in my child theme functions.php file which makes it seem even more odd to me.

    Are there any options that have worked for others?

    Unfortunately, my site is on my local server, so I don’t have a link.

    Thanks in advance for any help

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

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    How have you been linking a local javascript file?

    Thread Starter bguy0501

    (@bguy0501)

    I have tried using every form of enqueueing I’ve found online. Below is an example of one that I’ve tried.

    ‘<?php
    function wp_adding_scripts() {
    wp_register_script(‘myscript’, get_stylesheet_directory_uri()(‘/js/script.js’), array(‘jquery’),’1.1′, true);
    wp_enqueue_script(‘myscript’);
    }

    add_action( ‘wp_enqueue_scripts’, ‘wp_adding_scripts’ );

    ?>’

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Does that script tag render on the page?

    Thread Starter bguy0501

    (@bguy0501)

    Sorry, I’m not sure what you mean by that.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Right click on your page and select the option “view source” (or similarly labelled). Then search the view-sourced page for the string “script.js”. Does that come up?

    Thread Starter bguy0501

    (@bguy0501)

    I don’t see it when I view the source code.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What plugins do you have active and inactive?

    Thread Starter bguy0501

    (@bguy0501)

    akismet, contact form 7, exclude pages from navigation, google analytics by yoast, ithemes security, jetpack, scroll triggered boxes, shareaholic, wp edit, and yoast seo

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Does anything else inside your functions.php file work?

    Thread Starter bguy0501

    (@bguy0501)

    Linking the css and script files are the only thing I’ve tried

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Try breaking your functions.php file by inserting a random string in an incorrect place. Does your website return an error/ white page?

    Thread Starter bguy0501

    (@bguy0501)

    No, it doesn’t.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you double-check that your child theme is active in the Appearance > Themes section of the dashboard?

    Thread Starter bguy0501

    (@bguy0501)

    Yup, I can see it’s active. Should I try creating the child theme with a plugin instead? I just created the files based on info I found online.

    Thread Starter bguy0501

    (@bguy0501)

    Hey Andrew,

    Thanks so much for your help so far. Can you think of anything else I should try?

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘trouble linking local javascript file to website’ is closed to new replies.