Can’t add classes using jQuery from a JSON string with get_body_class()

get_body_class() is going to return an array of classes, which is then (per code not published in your question) JSON encoded into that comma separated string. While you can manipulate that in JavaScript, the easiest thing to do is implode the string before encoding: $c = get_body_class(‘project’); $c = implode($c,’ ‘); You should have a … Read more

Multiple selec2.js file loaded by several plugins

is this normal that each plugins has its own version ? If the script isn’t registered by Core there isn’t much else a plugin/theme can do but register the script itself. If would be nice if there were some standardization, but that would be a tricky problem to solve. what could be the issue for … Read more

Multiple Media uploader output to input

As per comments try collecting the ids in an array and then setting the text field once: custom_uploader.on(‘select’, function() { var selection = custom_uploader.state().get(‘selection’); var ids = selection.map( function (attachment) { return attachment.id; }); $(“#media-input”).val(ids.join(‘,’)); });

JQuery UI not loading without explicit loading of jQuery

jQuery and the jQuery UI Slider are both registered by default by WordPress. In order to use them, all you should need to do is something like this: add_action( ‘wp_enqueue_scripts’, ‘wpse192997_load_slider’ ); function wpse192997_load_slider() { wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘jquery-ui-slider’ ); } Note, though, that WordPress uses jQuery in noConflict mode, which means that the … Read more

Checking length of string in an admin area field onblur with jQuery

There are a number of issues with your code but most importantly you need to call val on the text input. Here is how your make_year_created_equal_4_chars function might look: function make_year_created_equal_4_chars() { ?> <script type=”text/javascript”> // This is a shorthand for “jQuery(document).ready()” jQuery(function($) { $(‘#acf-field-artwork_created’).blur(function() { // Please notice the declaration of ‘selected_length’. // It … Read more

Admin Ajax is returning 0 and not Insert data

A 0 status from admin-ajax.php indicates that no “action” is being parsed. When you enqueue the script you are assigning a handle, this handle needs to be used when you use wp_localize_script and additionally you need to assign the url. https://codex.wordpress.org/Function_Reference/wp_localize_script wp_register_script( ‘some_handle’, ‘path/to/myscript.js’ ); wp_localize_script( ‘some_handle’, ‘object_name’, array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ) ); … Read more

Change zurb foundation top bar style on.scroll in wordpress theme using jquery and css

You need to fully reference jQuery throughout your code. It should be… jQuery(window).on(“scroll”, function() { if(jQuery(window).scrollTop() > 50) { jQuery(“.top-bar”).addClass(“active”); } else { jQuery(“.top-bar”).removeClass(“active”); } }); When in no-conflict mode you need to always reference jQuery in full and not use the $. No conflict mode exists to prevent conflicts when jQuery is used with … Read more

Conditional Tags – Multiple Categories

As Mayeenul said in the comment you can use: if($category[0]->name == ‘News’ || $category[0]->name == ‘home-news’) { … And to follow up on your comment about the title flashing in, this is because the jQuery is run after the browser has already rendered the content so there’s a brief moment when it’s shown before jQuery … Read more

Can’t execute jQuery before my script

Try two things – 1. Link your js using wp_enqueue_script action as under : add_action( ‘wp_enqueue_scripts’, ‘theme_name_scripts’ ); function theme_name_scripts() { wp_enqueue_script( ‘script-name’, get_template_directory_uri() . ‘/js/example.js’, array(‘jquery’), ”, true); } Third parameter in wp_enqueue_script() function will make sure jquery is loaded before your current js file. Inside your js file, replace $ with jQuery as … Read more

Duplicate “default” form with jQuery

I don’t know your html code, but here is how it will work. The idea is that you keep the original hidden elsewhere. HTML <button class=”add-form”>add form</button> <form id=”main-form”> <div class=”form-item row”> <input type=”text” name=”abc”> </div> </form> <div class=”stay-hidden original-form-item”> <input type=”text” name=”abc”> </div> CSS .stay-hidden { display:none; } JS // Add form jQuery(‘.add-form’).click(function() { … Read more