Hello readers, today we discuss about "How to add a simple jQuery script to WordPress?".
There are two way to add script in our wordpress.
In header.php file, and in function.php file
In header.php file you can put the below line into head section.
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery.min.js"></script>
or
<script type="text/javascript" src="<?php bloginfo('template_url');?>/js/jquery.min.js"</script>
In function.php file you can put the below code into it.
<?php
add_action( 'wp_print_scripts', 'themeName_scripts' );
function theme_scripts()
{
if ( !is_admin() ) :
wp_enqueue_script( 'theme-jquery-min', 'http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js' );
endif;
}
?>
0 Comment(s)