For some reason a js isn’t running on a page on my wordpress development site called ‘information’. The page template was copied from a page which successfully runs the script so I’m not sure what’s missing. I’ve tried to remedy the situation by running this script in the functions.php file:
function my_scripts() {
if( is_page( array( 'information') ) ){
wp_enqueue_script( 'variable_fonts', 'js/variable_fonts.js', array(), '1.0.0', true );
}
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
I’ve also tried running this script on the page itself:
<script>
if(location.pathname=="/information/")
script.src = /js/variable_fonts.js;
</script>
Neither option is working. Am I missing something?
2
Answers
So with a bit more digging I realised I'd forgot to close the page after chopping out the get footer and get sidebar stuff from the bottom of the page, which was causing the scripts not to load. All fixed now by adding:
You forgot to call the function. Just add
my_scripts()
to the end of your file