Reputation: 57226
How come there is option to get child theme's js files in WP?
I only can get the child theme's css files like this,
wp_enqueue_script( 'custom', get_bloginfo('stylesheet_url') . '/js/custom.js', array() );
But I want to get the js files in the js folder in my child theme.
Is it possible?
EDIT:
With this,
$jsPath = get_stylesheet_directory() . '/js/yourScript.js';
wp_enqueue_script( 'child-js', $jsPath, array(), '1.0', true )
I will get:
http://{127.0.0.1}/projects/mysite/var/www/projects/mysite/wp-content/themes/vantage-child/js/custom.js?ver=1.0'
Which is wrong even though it gets the child theme folder correct - but adds extra path which i don't need var/www/projects/mysite/
Upvotes: 0
Views: 926
Reputation: 785
You could use get_stylesheet_directory_uri() which gets the theme folder path uri - see: https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri. Then just reference your JS files using something like.
$jsPath = get_stylesheet_directory_uri().'/js';
wp_enqueue_script('js-file', $jsPath.'/script.js', array(), '1.0', true);
Upvotes: 2