understrap-child
understrap-child copied to clipboard
can't add functions in custom-javascript.js
functions declared in custom-javascript.js file are not working,
function fbwindows(object) { window.open( object, "_blank", "height=380,width=660" ) }
console error: fbwindows is not defined.
I'm having a similar issue, the code inside the custom-javascript.js file doesn't get included into the child-theme.js file when you build it.
I discovered that is seems to not compile any functions written in that file but plain JS it will include.
Correct- if you don't export the function itself, it won't be available globally. I believe you can assign it to window to quickly solve this.
In the parent theme we're still working out some of the JS bundling stuff to make it easy- and once that release happens, we'll bring those updates to the child theme.
@bacoords thanks for the clarification.
What if you want to add a new js file? I can't seem to figure out the correct path for it in functions.php. I'm pretty sure I don't have to dump ALL my js into that one file 'custom-javascript.js' but I can't figure out the right way to link another js file. Console keeps saying my js file is not found.
What if you want to add a new js file? I can't seem to figure out the correct path for it in functions.php. I'm pretty sure I don't have to dump ALL my js into that one file 'custom-javascript.js' but I can't figure out the right way to link another js file. Console keeps saying my js file is not found.
@currentcreative That's just normal WordPress enqueuing. Just follow the format that they use for enqueuing the child scripts.
wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $the_theme->get( 'Version' ), true );
Also, here's a link to the documentation on the wp_enqueue_script function. If you're seeing a console error that the file isn't found, check the second parameter in the function (the src path) to make sure you're providing the right path to the JS file.
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
Please ignore, I see I shouldn't have asked this here now.
@currentcreative please create a discussion item, what you are asking for assistance with has nothing to do with the current issue we were discussing. Thanks.
Closing due to inactivity- please re-open if needed.