WordPress Codesnippets

add script to header

				
					
				
			

get_stylesheet_directory_uri() . ‘/js/custom_script.js’,
array( ‘jquery’ )
);
}
add_action( ‘wp_enqueue_scripts’, ‘my_scripts_method’ );
?>

This code is used to load a custom script in wordpress. The script is loaded using the wp_enqueue_script function. This function takes 3 parameters. The first is the name of the script. The second is the path to the script. The third is an array of dependencies. In this case, the script is dependent on jquery. The script is then loaded using the add_action function.

Was this code snippet helpful?
YesNo

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »