Last active
August 23, 2019 00:28
-
-
Save CFranc111/d7e4c1c2b08baf7371f9da13c23dd69b to your computer and use it in GitHub Desktop.
Wordpress jQuery cookie example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_main_scripts() { | |
// Enqueue plugin here, if needed, including array('jquery') as the 3rd argument as a dependency (see below) | |
// Enqueue custom javascript file | |
wp_register_script( 'my-scripts', get_stylesheet_directory_uri() . '/myfile.js', array('jquery'), filemtime( get_template_directory() . '/myfile.js' ), true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'custom_main_scripts' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function( $ ) { | |
$(document).ready( function() { | |
if (!!$.cookie('textfield1')) { | |
// existing cookie found - get cookie | |
$(".textfield1").val( $.cookie("textfield1") ); | |
} else { | |
// no cookie found - set cookie | |
$(".textfield1").change(function() { | |
$.cookie("textfield1", $(".textfield1").val(), {expires: 7}); | |
}); | |
} | |
}); | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment