WordPress: Sortable Metabox Fields Not Saving Position

Normally it should be enough to simply enqueue the postsbox script on a page where you want to have sortable meta boxes. Simply do the following: add_action( ‘admin_enqueue_scripts’, ‘wpse112022_postbox_enqueue’ ); function wpse112022_postbox_enqueue( $hook_suffix ) { // uncomment the next line to see what the $hook_suffix of your desired page is # var_dump( $hook_suffix ); if … Read more

Add `datetimepicker` to form

You can try this. add_action( ‘wp_enqueue_scripts’, ‘wpcustom_enqueue_script’ ); function wpcustom_enqueue_script() { wp_enqueue_style( ‘datepicker-style’, ‘https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css’ ); wp_enqueue_script( ‘js-datepicker’, ‘https://code.jquery.com/ui/1.12.1/jquery-ui.js’, array(‘jquery’), null, true); } Readmore: http://jqueryui.com/datepicker/

WP set auth cookie using Ajax is not saved to browser

I assume that your custom dashboard is on a different domain/subdomain than the WordPress installation. Cookies can only be set for the current domain. Typically cookies will not work cross domain. So your dashboard cannot create a cookie for the WordPress website. Theoretically it’s possible to bypass with some server configurations, but this technique has … Read more

inject js after redirect

I figured out a solution that ended up being along the lines of the suggestions offered (though it felt like more work than I should have had to do just to inject some js on the page). I appended a variable to my redirection url: wp_safe_redirect(esc_url(add_query_arg(‘failed_authentication’, ‘1’, ‘/register’))); I registered the parameter variable using: add_query_vars_filter($vars) … Read more

call shortcode in javascript

Javascript code is running in the user’s browser and not on your server (where your wordpress content resides). You could use ajax to call the function which the shortcode is pointing to. Here is how I handle AJAX calls with WordPress: 1) I use a jQuery ajax function to call the wp-admin/ajax.php jQuery.ajax({ url: yourSiteUrl … Read more

How can I add a jQuery OnClick event to the Publish posts button?

You can hook into the post footer actions (based on this answer, not tested): add_action( ‘admin_footer-post-new.php’, ‘wpse_80215_script’ ); add_action( ‘admin_footer-post.php’, ‘wpse_80215_script’ ); function wpse_80215_script() { if ( ‘post’ !== $GLOBALS[‘post_type’] ) return; ?> <script> document.getElementById(“publish”).onclick = function() { if ( confirm( “Ready?” ) ) return true; return false; }</script> <?php } These actions are called … Read more

How to get a jQuery script to run on a page?

Your question is a bit broad. We actually have a one question per post policy. I’m going to try to answer though My first question is, shouldn’t most themes that you download out there automatically include jQuery in your header anyway? Well, basically correct. So many features today in a theme needs jquery to run … Read more

AJAX function returning -1

You are passing ‘eu_custom_query’ as the action in your AJAX. It should be ‘custom_query’. You decide the action name, when you add the action i.e. ‘wp_ajax_my_action’ would be called ‘my_action’ You are confusing it with the callback method. Hope that makes sense. p.s. to fix your code change: add_action(‘wp_ajax_custom_query’, ‘eu_custom_query’); add_action(‘wp_ajax_nopriv_custom_query’, ‘eu_custom_query’); to: add_action(‘wp_ajax_eu_custom_query’, ‘eu_custom_query’); … Read more

Custom function to rearrange attachments when creating posts – Almost there

I’m not entirely sure what your intentions are for the code, and unfortunately i didn’t find what you provided worked very well, so i rewrote parts of the code supplied to make it into a more workable solution. This code will work for saving the attachment order in the metabox on save, not via ajax, … Read more