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

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

Get ACF value in external jQuery document

Your question is not entirely clear, but it looks like you are in need of wp_localize_script, which allows you to pass variables from PHP to a script. You would use it like this (example with two fields): add_action (‘wp_enqueue_scripts’,’wpse244551_add_field’); function wpse244551_add_field () { $my_field = array (); $my_field[] = array (field1 => get_field (‘field1’)); $my_field[] … Read more

jQuery Hoverintent plugin in TwentyEleven Menu [closed]

Here is the code I have in my functions.php file: /** * Hoverintent Plugin for the menu * @since Theme 1.0 */ function theme_hover_menu() { wp_register_script(‘hoverintent_script’, get_template_directory_uri() . ‘/js/hoverintent.js’, array(‘jquery’), ‘r6’ ); wp_enqueue_script(‘hoverintent_script’); } add_action(‘wp_enqueue_scripts’, ‘theme_hover_menu’); This is step 1… Next? Comments? Solutions? I will edit this post once I will have found the answer. … Read more

Comment form vaildation

Ok, I’ve worked this out. You need to copy the complete first section of the `comment_form()’ from wp core. This is the code <?php function comment_form( $args = array(), $post_id = null ) { if ( null === $post_id ) $post_id = get_the_ID(); else $id = $post_id; $commenter = wp_get_current_commenter(); $user = wp_get_current_user(); $user_identity = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)