Using page-id-{ID} from body_class() in local dev, versus live staging

You could use slugs instead of IDs. Taken from the Starkers theme (add it to your functions.php): add_filter( ‘body_class’, ‘add_slug_to_body_class’ ); function add_slug_to_body_class( $classes ) { global $post; if( is_home() ) { $key = array_search( ‘blog’, $classes ); if($key > -1) { unset( $classes[$key] ); }; } elseif( is_page() ) { $classes[] = sanitize_html_class( $post->post_name … Read more

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

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

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

All AJAX requests return a 400 error

I have not tested your code, but one problem I noticed is the contentType property in your $.ajax() call: contentType: ‘application/json; charset=utf-8’, because that way, (from the PHP side) the action (i.e. ajax_load_more) is not available in $_REQUEST[‘action’] which WordPress uses to determine the AJAX action being called, and when the action is not known, … Read more

WordPress admin-ajax.php 400 bad request

Your full form code does contain a hidden input named action with the value send_form. However, you’re not sending it correctly, because of the the contentType part in your JS script, which submits the form data as a JSON payload, but note that the old admin-ajax.php endpoint doesn’t support JSON payload, hence $_REQUEST[‘action’] would be … Read more