In my site I use some jQuery and when I'm in development mode everything works fine.
But when I disable development mode jQuery doesn't load. I checked in console and site source. What's even wierder uikit components wchich use jQuery (like slideshow) works fine.
Do I have to enque jquery somehow?
Hello Mariusz,
I'm not sure about this but read Avoiding Conflicts with Other Libraries. This might help you.
Hey Mariusz,
You are the second person reporting this which makes me think their might be a conflict somewhere. Could you kindly post a link to your site so that I can take a look?
Thanks,
Sure, but please remove link later π
Linked removed as requested
I noted that jQuery doesn't load only when:
-
Compile all WordPress scripts (Aggressive mode, in Standard mode works fine).
- Compile all WordPress styles is enabled. In this case also imported fonts don't load. I'm using @import method in less file to load font from Google CDN.
Thanks for the added information. I am doing some testing and might need more details from you to replicate this issue.
I will update this thread soon π
Hi Mariusz,
Thanks for sending me your credential via PM so that I could look at your website. This issue is that you are adding an inline script using jQuery within your content (in your add_logo_info()
function).
When you enable Beans JavaScript Compiling option set to Agressive, it will compile all the JavaScript and load it at the bottom of the page (for optimization purposes). Because your inline script is called in the content which is before jQuery loads in this case, it throws and error.
What you have to do if you really want it to have it inline is print it in the footer. So you would do the following:
add_action( 'wp_footer', 'example_footer_script', 20 );
function example_footer_script() {
?>
<script type="text/javascript">
// You JS which depends on jQuery.
</script>
<?php
}
Note how I have set the action priority to 20 to make sure it loads after Beans Compiler.
Another approach would be to add a /assets/js/home.js
file containing your custom JavaScript for your home page. Then you would add it to the UIkit compiler using the following snippet in your current home.php
which will automatically create a specific compiled file with all your JavaScript (include jQuery, Uikit etc.) only for your home page:
add_action( 'beans_uikit_enqueue_scripts', 'example_view_enqueue_uikit_assets' );
function example_view_enqueue_uikit_assets() {
beans_compiler_add_fragment( 'uikit', get_stylesheet_directory() . '/assets/js/home.js', 'js' );
}
Which ever option you go for, this should fix your jQuery error when you have the Beans JavaScript Compiler option enabled and set to Agressive π
Happy coding,