wp_enqueue doesn’t work

First Hint: Copy your parent theme (without modifications) and start a new child theme that only contains the style.css file with the comment and a plain functions.php file. You can move stuff later, but this way you can make sure that nothing interrupts. Solve one task after each other in this plain vanilla setup. Second … Read more

Deregister multiple scripts using a function?

First, you’re attempting to deregister too late. You need to use wp_enqueue_scripts, rather than wp_print_scripts. Second, all you need to do is add a call to wp_deregister_script() for each script you need to deregister: <?php add_action( ‘wp_enqueue_scripts’, ‘my_deregister_javascript’, 100 ); function my_deregister_javascript() { if ( !is_page(array(‘order’, ‘shopping-cart’, ‘checkout’) ) ) { wp_deregister_script( ‘tcp_scripts’ ); // … Read more

wp_enqueue_script not loading my custom js file

You need to reference your WordPress template directory when you register the script. Change this: wp_enqueue_script(‘my_javascript_file’, ‘/javascripts/app.js’, array(‘jquery’)); …to this: wp_enqueue_script(‘my_javascript_file’, get_template_directory_uri() . ‘/javascripts/app.js’, array(‘jquery’)); Codex reference: get_template_directory_uri()

wp_enqueue_script before wp_head

Enqueue mechanics and suggested ways to use them serve flexibility and interoperability. Simply put consider what would be the easiest way for third party code to modify mechanics of yours? Hardcoding things in template often makes editing that template the only viable option. Manipulating hooks is typically more convenient and less problematic than that. On … Read more

Trying to get custom js files in my admin header

Ahh ok I figured it out while researching. I needed to add the $hook parameter and pass it to my function like so: function my_admin_enqueue_scripts($hook) { global $current_screen; if ( ‘post.php’ != $hook ) return; wp_register_script(‘my-scripts’, get_template_directory_uri() . ‘/js/custom/my-scripts.js’ ); wp_enqueue_script(‘my-scripts’); wp_localize_script(‘my-scripts’, ‘wp_ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); } This gave me the results … Read more

Enqueue script inside IE conditional comments

Change <!–[if (gte IE 6)&(lte IE 8)]> <?php function blarg(){ wp_enqueue_script(‘selectivizr’, get_template_directory_uri() . ‘assets/js/vendor/selectivizr.js’); } add_action(‘wp_enqueue_scripts’, ‘blarg’, 101); ?> <![endif]–> to <!–[if (gte IE 6)&(lte IE 8)]> <script src=”<?php echo get_template_directory_uri(); ?>/assets/js/vendor/selectivizr.js” type=”text/javascript”></script> <![endif]–> wp_enqueue_script() should only be used in a functions.php file.

jQuery does not work

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. … Read more