Add X meta box inputs based on form at top of meta box, how to do it right?

You could clone an existing field with jQuery and append it to the form. You’ll also have to handle cases where the number of ingredients is fewer than the number of fields, and you’ll have to use jQuery’s remove. Here’s a simple example of cloning a field: $(‘#quantity-form’).submit(function(){ // get # of fields that already … Read more

WordPress Featured Post Slider

This is one of those things you probably have to do yourself, even though there are some slider plugins, they are difficult to customize. Using a jquery slider is pretty straightforward, they are usually just controlled with ID’s and CLASS’s, so you can wrap any WordPress code, for instance a wp_query (for featured posts). toscho’s … Read more

Best Way to Include Scripts on a Specific Template Page

The following (in your theme’s functions.php) will register your script, and set jQuery as a dependency. So when you enqueue it, jQuery will also be enqueued. function my_scripts_method() { // register your script location, dependencies and version wp_register_script(‘my_custom_script’, get_template_directory_uri() . ‘/js/custom_script.js’, array(‘jquery’), ‘1.0’ ); } add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); You can then enqueue your script one of … Read more

Basic WordPress AJAX Call

WordPress AJAX uses actions to connect your jQuery action with a traditional WordPress action. Take a look at the example WordPress provides in their docs. There’s 2 hooks: add_action( “wp_ajax_{$jquery_action_string}”, “callback_function_name” ); The above will only work for authenticated ( logged in ) users. For non-logged-in users we use nopriv: add_action( “wp_ajax_nopriv_{$jquery_action_string}”, “callback_function_name” ); So … Read more

Adding fields to the media uploader with jquery listeners

From Blackbone.js website: render is the core function that your view should override, in order to populate its element (this.el), with the appropriate HTML. The convention is for render to always return this. So, I have modified the code a little bit to add jQuery change listener. function add_gallery_type_option(){ ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> … Read more

Is it worth updating WP admin to jQuery 1.5?

Well, as for performance release post says: In this release we’ve also been able to improve the performance of some commonly-used traversal methods: .children(), .prev(), and .next(). The speed-ups that we’re seeing are quite substantial (potentially many many times faster, depending upon the browser). On other hand replacing jQuery on admin side is rarely good … Read more

Uncaught TypeError: Cannot read property ‘replace’ of undefined

In WordPress jQuery is loaded in noConflict mode, it means that you need to use jQuery instead of the dollar sign $ You could wrap the code in an anonymous function (technically any IIFE) where you pass in jQuery to be mapped to $ and combine this with document ready, like this: jQuery(document).ready(function($) { // … Read more