I have a page template that needs jQuery loaded in the header instead of the footer.
The Theme (Divi Theme) loads jQuery in the footer by default. This causes some errors, when jQuery is loaded twice.
Is there any way I can modify <?php wp_footer(); ?>
to exclude jQuery for this template?
Thanks.
Template:
<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="<?php echo get_site_url(); ?>/cam-forms/styles/cam-forms.min.css" />
<script type="text/javascript" src="<?php echo get_site_url(); ?>/cam-forms/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo get_site_url(); ?>/cam-forms/js/jquery-migrate.min.js"></script>
</head>
<body>
<?php echo do_shortcode( get_field('form') ); ?>
<?php wp_footer(); ?>
</body>
</html>
2
Answers
You have to add
<?php wp_head(); ?>
in the following place:Then, in you file functions.php add this..
Also I always suggest you to work with the minified files for CSS and JS.
add below function in function.php for add js and css file in header and remove file in footer