Wednesday, October 9, 2013

How to Include Custom Javascript in Wordpress (wp_enqueue_scripts)

Hiiii, those who uses wordpress for web developent must be knowing this and those who are new to wordpress. to them I want to tell tell that you can't just use our javascript code in wordpress same as we use in core PHP.
In wordpress all the '$' in jQuery code must me replaced with 'jQuery' and you don't have to include "jQuery js" beacause wordpress itself provides a support for jQuery.
In wordpress , you can't use the javascript code written by you anywhere in rest of your code rather after writing your code anywhere in you website, you have to send that javascript code to wordpress site 'header'.
To perform this function of sending and including a custom javascript code in wordpress , a function namely- wp enqueue script is used. So. in this post I wiil telling how to use wp enqueue script function to make your javascript code work in wordpress.



CODE BEGINS :

<?php
function my_scripts_method() {
wp_enqueue_script(
'jquery.flexslider',
plugins_url() . '/webauctioneers_banner/js/jquery.flexslider.js',
array( 'jquery' )
);
wp_enqueue_script(
'webauctioneers',
plugins_url() . '/webauctioneers_banner/js/webauctioneers.js',
array( 'jquery' )
);
wp_enqueue_script(
'shCore',
plugins_url() . '/webauctioneers_banner/js/shCore.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
?>

Hope you like this post……..Please Comment…………!!!!!!!!!


Tags: ,

0 Responses to “How to Include Custom Javascript in Wordpress (wp_enqueue_scripts)”

Post a Comment

© 2013 MyCodeStock. All rights reserved.
Designed by SpicyTricks