0

So, I'm trying to mess around with WordPress and I've run into a simple issue that I can't find answers to on the codex... probably 'cause its a simple fix. :)

I've got a functions.php file that is attempting to call an external js file like so:

function place_theme_scripts() {
wp_register_script( 'javascripting', get_template_directory_uri() . '/js/rspnsv.js',   array(), '1.0.0', true );
wp_enqueue_script( 'javascripting');
  }
  add_action( 'wp_enqueue_scripts', 'place_theme_scripts' );
  ?>

The my 'rspnsv.js' file is under my themes directory in a file called 'js'. Seems simple enough, but this isn't working. Its not the javascript, since it runs smoothly when I place it inline. I'm clearly messing up something simple with this whole wordpress php function. Can anyone spot anything? Give me a pointer? Thanks!

5
  • Seems right at first glance? Open the page, hit "view source" and search for rspnsv.js, should be in the footer, check that the file is added, and that the script tag and the path are outputted correctly etc. Commented Jan 27, 2014 at 0:15
  • in your question you said it is in a file called 'js' - I assume it is a typo and you wanted to write a folder called JS ?? anyhow, did you, for sake of testing / developing, enqeued another script with the same handle ?? (javascripting) - try changing the handle name to something else .. Commented Jan 27, 2014 at 2:13
  • view source yieled nothing, adeneo. Obrnerk, it is indeed in a folder called js... I'm still stuck Commented Jan 28, 2014 at 1:42
  • also, of note: my functions.php runs fine, since I use it to 'widgitize' a section of my page... I'm super lost here. Commented Jan 28, 2014 at 2:02
  • So, I gave up and ended up just throwing this in the <head> : <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/tester.js"></script> Any reason, this is a bad way to go? Commented Jan 29, 2014 at 1:13

3 Answers 3

2

one possible issue.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Rob. This is a theme I created from scratch, so I don't think it'll fall under this category. In any case, I tried out get_stylesheet_directory_uri to no avail. Could the fact that I'm hosting it locally be messing this up? I guess, that makes no sense
0

Try using get_stylesheet_directory_uri instead of get_template_directory_uri

Comments

0

Hopefully, this will help those that might run into this issue. I ultimately fixed the problem by copying and pasting the codex's code example and inputting the needed file names, etc.

I still don't know what I did wrong, but I should have just copied the codex in the first place and gone from there so as to avoid any typo issues (seeing as I'm no php dev ).

Hope that helps.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.