There is an Edit at the end of this question.
I want to to include a file, in a script tag, from the js sub directory of the theme's directory. I want to do so in the theme's index, search, single, archive, etc. php files.
The URL of the theme I'm using is: http://www.example.com/welg/wp-content/themes/mytheme
The script tag would be:
I tried the get_theme_root() function but I get nonsense. Well, at least nonsense in terms of a directory usable for my purposes.
What is be returned is a path that starts pretty much at the top of the hosting server's directory structure.
That output is useless for any purpose except, perhaps direct access, via the operating system, on the server itself by someone at the server's console.
The return value I expected from get_theme_root() was:
/welg/wp-content/themes/themedir (with or without a trailing slash)
I tried all the "get" theme functions I could find and the site_url and home_url
Here's the ouput from all of them (I added h's to the front of the http:// text to get past my limit of only being able to post two links. Just ignore the extra h's.
Here's the output from the various functions:
get_theme_root_uri()-- http://www.example.com/welg/wp-content/themes get_theme_root() -- /hermes/bosoraweb081/b1107/myd.sugarcatsimon/public_html/pdmeoff/pdroot/welg/wp-content/themes get_theme_roots() -- /themes site_url -- http://www.example.com/welg home_url http://www.example.com/welg
Am I missing something? Is there another function which will return the path, relative to the site root or WP root, for the currently used theme's directory?
I guess I could use the output from get_them_url(), make my link a fully qualified link, not a relative link, and suffix the name of the theme and the /js/filename.js but I'd like a better solution which does not rely on knowing any of the directory names, such as the current theme's name/directory.
One other thing - I habitually use www.example.com as the domain in examples I post online, and most sites tell you to use it, but I had never really thought it through.
I just realized that there my be an actual site with that domain name. So, I entered www.example.com into the browser address bar and I got - well, try it yourself. It is very interesting.
In response to the person who wrote the answer saying that I should enqueue and register scripts -
What does it mean in WP Land when the words enqueue and register are used?
What are the benefits, as regards WP, of enqueuing and registering functions as you show it being done?
Just because those who wrote WP do something in a particular way does not mean it can only be done that way or it is the best way.
I would really like to know the principles of enqueuing and registering functions as apply to WP.
I am new to WP but most certainly new to computing. I've been in computing since 1973, some 42+ years.
In the PC world, it is far too often the case that words which have been in use for decades, with specific agreed upon meanings, are used for new meanings.
There is also a propensity for the invention of new terms for meanings that are already covered by existing terminology.
Quite often, what an "old timer" calls a rose is actually not a rose, in the PC world. When terms with established meanings are used in computing (or any technical area) for other purposes, communication suffers.
Poor communications breeds poor design and code.
Thanks for the reply and I really would like to understand those words in relation to WP.