Fall Back Google CDN in JavaScript

Scripts don’t get printed at the wp_enqueue_scripts hook, but rather at the wp_print_scripts hook. That said: don’t echo/print scripts, period. Instead, enqueue them properly. Caveat: This method is Plugin territory, and should not be included as Theme code in a publicly distributed Theme. You deregister jQuery, but the step you’re missing is registering and enqueueing … Read more

wp_enqueue_ scripts

No, that’s not right. Your script is located at http://www.olliedaw.co.uk/wp-content/themes/Daw%20Refrigeration%20Milk%20Tanks/js/excerpt.js and you’re enqueueing http://www.olliedaw.co.uk/wp-content/themes/DawRefrigerationMilkTanks/js/excerpt.js … those are not the same file! This happens often when you have spaces in your file names and directories. Either remove the spaces or explicitly escape them as %20 when you queue them with wp_enqueue_script().

Using Bootstrap Switch with WordPress

I had a try with that. You’ll need Twitter Bootstrap‘s CSS file, Bootstrap Switch‘s CSS and JS files. I put all those three files in a folder called assets. functions.php: <?php add_action( ‘wp_head’, ‘rr_bootswitch_meta’ ); add_action( ‘wp_enqueue_scripts’, ‘rr_bootswitch_enqueue’ ); function rr_bootswitch_meta(){ print ‘<meta http-equiv=”X-UA-Compatible” content=”IE=9; IE=8;” />’; } function rr_bootswitch_enqueue(){ wp_enqueue_style(‘bootstrap-css’, get_template_directory_uri() . ‘/assets/bootstrap.min.css’ ); … Read more

Dropdown filtering extremely slow

I’m surprised it’s all that slow but you can remove all but one of the database calls & most of the looping by passing the term data instead of just slugs to my_dropdown_categories() so get_terms() doesn’t have to be called, plus a few other improvements (see comments) eg: function my_dropdown_categories( $taxonomy, $current_selected = ”, $terms … Read more

Reload wordpress shortcodes

If you want to do this via AJAX, on the server side you could do something like the following: add_action( ‘wp_ajax_nopriv_update_shortcode_content’, ‘update_shortcode_content’ ); function update_shortcode_content(){ if( !empty( $_GET[‘new_shortcode_value’] ) ){ $updated_content = do_shortcode( ‘[theshortcode value=”‘ . $_GET[‘new_shortcode_value’] . ‘”]’ ); wp_send_json( array( “content” => $updated_content ) ); } }

Adding JS to one page

Create a new dir and file dedicated to your javascript. /js/scripts.js. Wrap your entire javascript like this: ( function( $ ) { var allStates = $(“svg.us > *”); allStates.on(“click”, function() { allStates.removeClass(“on”); $(this).addClass(“on”); }); } )( jQuery ); Then in your theme’s functions file, put this code. It loads your new js file. function your_scripts() … Read more