The value of attribute [ data-type ] must be in double quotes – custom html widget error

change it to CSV data-type=”Information Gathering, Farming & Husbandry, Delivery Service, Emergency Response, Remote Inspections, Mapping & Surveying, Maritime Success, Military & Defense Support, Scientific Research, Real Time Surveillance ” then do var toRotate = elements[i].getAttribute(‘data-type’).split(“, “); the .split(“, “) turns the CSV string into an array. then do new TxtType(elements[i], toRotate, period); the toRotate … Read more

Can’t get JS code to work with shortcode

You need to return the Shortcode generated string, not echo, like this: function gg_product_front_end() { wp_register_script( ‘gg_loadProducts_frontEnd’, plugins_url( ‘js/front_end.js’, __FILE__ ), array( ‘jquery’ )); wp_enqueue_script( ‘gg_loadProducts_frontEnd’ ); return ‘<p id=”test”>Test!</p>’; } Also, you need to call the JavaScript function, like this: function gg_loadProducts_frontEnd() { console.log( ‘Test!’ ); } gg_loadProducts_frontEnd(); Otherwise Test! will not be logged … Read more

admin-ajax.php HTTP400: BAD REQUEST – The request could not be processed by the server due to invalid syntax

You can’t send the data to admin-ajax.php as JSON: data: JSON.stringify({ action: “process_coupon” }), For the wp_ajax_ actions to be fired, WordPress checks $_REQUEST[‘action’], but this is not populated by PHP when the form is submitted as JSON. The correct way to send the request with jQuery is to pass the data like this: data: … Read more

wp_register_script unable to link bootstrap JS

function load_js() { wp_register_script(‘bootstrap’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array(‘jquery’), false, true ); wp_enqueue_script(‘bootstrap’); } add_action(‘wp_enqueue_scripts’, ‘load_js’); Use with array(‘jquery’) instead of ‘jquery’ Refference here. It says: use array.

Properly applying nonce to a form using AJAX

You just need to send the nonce along with your AJAX data: $.ajax({ type: ‘POST’, url : profile_edit.ajaxurl, data: $(‘#profile_update’).serialize() + ‘&my_nonce=” + profile_edit.nonce + “&action=update_profile_post’, // don’t forget the action name! }); Alternatively, since you’re using jQuery’s serialize() function, you could just add the nonce directly in the form: <?php wp_nonce_field( ‘update_profile_validation’, ‘my_nonce’ ); … Read more

Changing Font-Size based on specific Font thru javascript

Not exactly what you asked for, but you can kind of “make sure” the user has the desired font through the @font-face css3 rule. According to caniuse.com about 95% of global users can use that css property, so it’s a good trade-off. Different browsers use different font formats however, so you’ll need to use http://www.fontsquirrel.com/fontface/generator … Read more

How can I make the “Preview Post” button save and preview in the same window?

Here’s a way to do it without modifying the core: add_action(‘admin_footer’,’preview_same_window’); function preview_same_window(){ ?> <script type=”text/javascript”> jQuery(function($){ jQuery(‘.preview.button’).unbind().removeAttr(‘target’); setTimeout(function(){ jQuery(‘.preview.button’).unbind().removeAttr(‘target’); },250); }); </script> <?php }

How to get this JavaScript working with get_permalink

Probably the best way to do this is as suggested above by using wp_localize_script. You haven’t mentioned how you’re including the javascript – but I’m going to assume you’re doing it the WordPress way. So, something like this: add_action( ‘wp_enqueue_scripts’, ‘wwm_enqueue_scripts’ ); function wwm_enqueue_scripts() { //see the documentation if you don’t understand what’s going on … Read more

Elegantly using JavaScript on widget admin forms

One way around this I’ve discovered since posting the above question is to instantiate inline via WP_Widget::form(), with wp_enqueue_script() loading the necessary JavaScript (exactly as mentioned above) — except, and here’s the key part, load the JavaScript in the header instead of the footer (fifth argument of wp_enqueue_script()). Which makes a lot of sense now … Read more