Enqueue jQuery in WordPress

You’re on the right track, but missing one piece: add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); add_action allows you to run code at specific times during page loads / specific events. The above action tells WP to run your function when it is adding the scripts to the html head element. Your function in turn instructs WP to add the … Read more

wp_localize_script, variable is not defined in jquery

wp_localize_script should be called AFTER wp_enqueue_script: IMPORTANT!: wp_localize_script() MUST be called after the script it’s being attached to has been enqueued or registered. It doesn’t put the localized script in a queue for later scripts. Fix it in your function: function my_action_callback() { wp_enqueue_script(‘jscustom’); // I assume you registered it somewhere else wp_localize_script(‘jscustom’, ‘ajax_custom’, array( … Read more

How wp_enqueue_script works?

In simple case you need to enqueue script before header scripts are printed, which happens in wp_head hook. Basic approach would be this in functions.php of your theme: add_action(‘wp_enqueue_scripts’, ‘my_enqueue_scripts’); function my_enqueue_scripts() { wp_enqueue_script(‘jquery’); }

jQuery in WordPress – Why is it not working?

just to help a bit further … WordPress runs jQuery in ‘safe’ mode which means in WordPress you need to write code like this jQuery(document).ready(function() { and not like this $(document).ready(function() { But what the HTML5BP has done is added this funky bit of code (probably kindly to help Developers) // remap jQuery to $ … Read more

Use latest jQuery in WordPress (admin interface)

Starting with version 3.6 WordPress actively discourages from deregistering “critical” scripts in admin at all. For posed scope (loading newer jQuery in specific part of admin) it would make more sense to load custom copy of jQuery normally and use noConflict() on it right away to isolate it in own variable to be used in … Read more

Execution of JavaScript on save post

Do it like shown below, as suggested by @gyo and done by @Howdy_McGee in his answer. function admin_queue( $hook ) { global $post; if ( $hook == ‘post-new.php’ || $hook == ‘post.php’ ) { if ( ‘targeted-posttype’ === $post->post_type ) { wp_enqueue_script( ‘custom-title-here’, bloginfo( ‘template_directory’ ) . ‘/scripts/custom-script.js’, ‘jquery’, ”, true ); } } } … Read more

How disable checkbox when listbox value changes in tinymce

Looking though the existing plugins, the standard tinymce way to do this is to save the popup window in a win variable: { text: ‘Vídeos’, onclick: function() { var win = editor.windowManager.open({ //etc And then use win.find(‘#name’) to target the control, eg: {type: ‘listbox’, name: ‘video_site’, onselect: function( ) { var autoplay = win.find(‘#video_autoplay’); if … Read more

How to Use JSON With AJAX?

Usually, you can use the global variable ajaxurl instead of any path using admin-ajax.php. More importantly, the PHP function should echo the response before calling wp_die(). Because you haven’t called wp_die(), AJAX is probably waiting for more from PHP. Hope this helps. P.S. What is that ‘json’ string doing where the AJAX fail() function should … Read more

Working Bootstrap Carousel Conversion to WP – Technical Questions

I had a similar situation recently, making a Bootstrap carousel dynamic. Here’s my functions.php code for that: //Images Slider function themename_slider_home_images_setup($wp_customize) { $wp_customize->add_section(‘home-slider-images’, array( ‘title’ => ‘Home Slider’, )); $wp_customize->add_setting(‘home-slider-first-image’); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, ‘home-slider-first-image’, array( ‘label’ => __( ‘First Image’, ‘theme_name’ ), ‘section’ => ‘home-slider-images’, ‘settings’ => ‘home-slider-first-image’ ) ) ); $wp_customize->add_setting(‘home-slider-second-image’); $wp_customize->add_control( new … Read more