I'm trying to run this jquery code on my archive page, but it gives me an error "undefined $". But it works outside of wordpress. I don't know what to do, I'm confused.
$(".show-more-posts").on("click", () => {
$(this).show();
});
Sorry if my question is stupid, I'm a novice.
CodePudding user response:
You would need to load jquery in wordpress. Use this code in functions.php file.
add_action('wp_enqueue_scripts', 'load_jquery_to_theme');
function load_jquery_to_theme(){
wp_enqueue_script('jquery');
}
And in your javascript file use this
jQuery(document).ready(($) => {
$(".show-more-posts").on("click", () => {
$(this).show();
});
});