Add Custom JavaScript and Stylesheet in wordpress

We can directly put it in the header section as we normal does but sometime it maynot work in case of admin.
We can include following code in function.php

function mytheme_custom_scripts() {

	if ( ! is_admin() ) {
		$scriptsrc = get_stylesheet_directory_uri() . '/js/';
		wp_register_script( 'myhandle', $scriptsrc . 'myscript.js', 'jquery', false );
		wp_enqueue_script( 'myhandle' );

add_action( 'wp_enqueue_scripts', 'mytheme_custom_scripts' );

and for case of css add the following code

 wp_enqueue_style('thickbox', get_bloginfo('siteurl') . 'wp-includes/js/thickbox/thickbox.css', false, false, 'screen');

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version