Share

So, there are times when certain JavaScripts use graphic files to decorate the content (for example gifs to show that slider is being loaded).

If we hardcoded the source then we would have to alter these changes while changing the domain or moving a WP to another site. So how to add these files without hardcoding the url?

Simply place the following before calling the actual script:

[javascript]

[/javascript]

While creating themes I usually enqueue files in the footer so placing that before the wp_footer(); would do the job.

For example:
[php]



[/php]

Then in your .js file add the following:

[javascript]
// some stuff before
preloadImage: templateDir + ‘/_ui/images/home/loading.gif’,
// … some stuff after
[/javascript]

Plus remember to call the scripts the proper way

The following two tabs change content below.
WordPress Blogger, Certified Codeable Expert Developer, Senior WordPress developer. Having worked with WordPress for over 8 years creating plugins, themes and WordPress based applications. I am wordpress.org contributor, CodeCanyon creator and YouTuber.