0

I'm not sure whats going on with my code here, I'm enqueuing scripts like so:

wp_enqueue_script( 'lightbox', '/wp-content/themes/'.get_stylesheet() . '/js/lightbox.js');

However when I view the source of my page, the script isn't being linked, rather all the js is being loaded into the head of the document like so:

<script type="text/javascript" style="display:none"><!--
/*!
 * Lightbox v2.9.0
 * Released under the MIT license
 * https://github.com/lokesh/lightbox2/blob/master/LICENSE
 */
!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof exports?
etc...

Is this the correct behavior? It seems to be causing conflicts with my other scripts? Many thanks.

3

You should not use relative URLs when enqueuing media items. Use the full URL instead.

There are two functions that can come in handy: get_theme_file_uri() and get_template_directory_uri().

So:

wp_enqueue_script( 'lightbox', get_theme_file_uri( '/js/lightbox.js' ) );

will be the correct syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.