For this example we are going to use a script from a sticky menu

First, add your script to a .js file located in your theme and make sure you wrap the code with the first and last lines:

jQuery(document).ready(function($){
$(window).scroll(function() {
if ($(this).scrollTop() > 160){ 
$('nav').addClass("sticky");
}
else{
$('nav').removeClass("sticky");
}
});
});

Next, add the following to your functions.php file


function my_assets() {
	wp_register_script( 'sticky-nav', get_template_directory_uri() . '/library/js/stickey-header.js', array( 'jquery' ), '1.0', true, all );
	wp_enqueue_script( 'sticky-nav' );
}
add_action( 'wp_enqueue_scripts', 'my_assets' );

You can change “my_assets” to whatever you want to call the functions.
You can change “sticky-nav” to whatever you want to call the script.
Make sure you update the directory path to the path of your above .js file.
Leave “true” as is to call the script in the footer or change it to false to call it in the header.

Leave a Reply

Get in Touch

Please fill out the form below and we will get back to you ASAP

  • This field is for validation purposes and should be left unchanged.