Skip to main content
Tweeted twitter.com/StackWordPress/status/1268150446679564290
added 569 characters in body
Source Link
MrKainig
  • 431
  • 1
  • 4
  • 10

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?

*Update @Pieter I adapted your change

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') ); 2

isThe Code looks now like this and it works, it did not work when I just added the function to the other add_action. Thanks everybody for the help! Still I wonder if there isnt a way to cut this code a little bit.

wp_enqueue_scriptadd_action( 'custom'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-script.js'style', get_stylesheet_directory_uriget_template_directory_uri() . 'js'/custom-scriptstyle.js'css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('jquery' 'parent-style' ) );

but it is still not working. This is what I have in my .js file and it works if I put it directly in page.php for example:

<script>}
if
/*add my custom jquery script*/
add_action(jQuery) {'wp_enqueue_scripts', 'menu_scripts' );
function menu_scripts() {
wp_enqueue_script( 'responsive-menu', get_bloginfo( 'stylesheet_directory' alert) . '/js/responsive-menu.js', array("jQuery library'jquery' is), loaded!"'1.0.0' );
 wp_enqueue_script(
} else {
  'custom-script',
   alert get_stylesheet_directory_uri("jQuery) library. is'/js/custom-script.js',
 not found!"  array( 'jquery' )
);
 
        }
<

What is this line for ?

wp_enqueue_script( 'responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/script>js/responsive-menu.js', array( 'jquery' ), '1.0.0' );

Is it necessary?

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?

*Update @Pieter I adapted your change

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

is now

wp_enqueue_script( 'custom-script.js', get_stylesheet_directory_uri() . 'js/custom-script.js', array('jquery') );

but it is still not working. This is what I have in my .js file and it works if I put it directly in page.php for example:

<script>
if (jQuery) {  
 
   alert("jQuery library is loaded!");
 
} else {
 
   alert("jQuery library is not found!");
 
 }
</script>

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?

*Update 2

The Code looks now like this and it works, it did not work when I just added the function to the other add_action. Thanks everybody for the help! Still I wonder if there isnt a way to cut this code a little bit.

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

/*add my custom jquery script*/
add_action( 'wp_enqueue_scripts', 'menu_scripts' );
function menu_scripts() {
wp_enqueue_script( 'responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script(
    'custom-script',
    get_stylesheet_directory_uri() . '/js/custom-script.js',
    array( 'jquery' )
);
        }

What is this line for ?

wp_enqueue_script( 'responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );

Is it necessary?

added 358 characters in body
Source Link
MrKainig
  • 431
  • 1
  • 4
  • 10

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?

*Update @Pieter I adapted your change

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

is now

wp_enqueue_script( 'custom-script.js', get_stylesheet_directory_uri() . 'js/custom-script.js', array('jquery') );

but it is still not working. This is what I have in my .js file and it works if I put it directly in page.php for example:

<script>
if (jQuery) {  
 
   alert("jQuery library is loaded!");
 
} else {
 
   alert("jQuery library is not found!");
 
}
</script>

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?

*Update @Pieter I adapted your change

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

is now

wp_enqueue_script( 'custom-script.js', get_stylesheet_directory_uri() . 'js/custom-script.js', array('jquery') );

but it is still not working. This is what I have in my .js file and it works if I put it directly in page.php for example:

<script>
if (jQuery) {  
 
   alert("jQuery library is loaded!");
 
} else {
 
   alert("jQuery library is not found!");
 
}
</script>
Source Link
MrKainig
  • 431
  • 1
  • 4
  • 10

I want to enqueue a .js file to my child theme

I tried to enqueue a custom .js file in my child theme directory.

In the functions.php of my child theme I find the following code

/* After this. you can override Accessible Zen's pluggable functions or add your own.
 * Remember, do your best to stay accessible! :)
 *
 */
 add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}

where only this part was implemented by me and is supposed to load my custom.script.js from the js/ folder

wp_enqueue_script( 'custom-script.js', 'js/custom-script.js', array('jquery') );

Unfortunately it doesn't do so, can anybody help?