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

WordPress REST endpoint not able to reach with jQuery

First, lets fix your endpoint: function wpc_ylp_rest_videos( ) { $myObj->name = “John”; $myObj->age = 30; $myObj->city = “New York”; $myJSON = json_encode($myObj); echo $myJSON; } There are a few problems here: callbacks for REST API endpoints are meant to return their data, like shortcodes. The REST API does the JSON encoding, you’re not meant to … Read more

Appending anchor tag to next post

You can alter the links for next_post_link and previous_post_link with a filter. function alter_npppl_wpse_100919($link) { return preg_replace(‘/href=”https://wordpress.stackexchange.com/questions/100919/([^”]+)”https://wordpress.stackexchange.com/”,’href=”$1#something”‘,$link); } add_filter(‘next_post_link’,’alter_npppl_wpse_100919′); add_filter(‘previous_post_link’,’alter_npppl_wpse_100919′); The URL you get will be the default URL plus #content. If your site is generating /page/2/ then the final URL will be /page/2/#content. If you don’t want that trailing slash– the one before the … Read more

Script dependencies for post.js

Because of the dependency handling built into the script registration system you should only need … wp_enqueue_script(‘post’); … to load all of the required scripts, which is exactly what the Core does. But just loading the scripts isn’t going to make everything work. That form is actually loaded by wp-admin/post.php, which requires wp-admin/admin.php which includes … Read more