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

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

Automatically decrease font size for long words

I’ve done something similar taking the simple approach of adding a CSS class to titles based on their character count. That CSS class then decreases letter-spacing and/or font-size. // Count the characters, taking Unicode into account $chars = mb_strlen($post->post_title); // For every 10 characters after the first 20, add a size $size = max(0, ceil(($chars … Read more

How do I use WP’s jQuery

WP’s jQuery is not mapped to $ like you may expect, it is loaded in noConflict mode so you’ll need to use jQuery() instead of $(), unless you map it yourself. When you include your js file you’ll want to make sure to set jQuery as a dependency as well: wp_enqueue_script( ‘your-script-handle’, get_stylesheet_directory_uri() . ‘/js/your-script.js’, … Read more

AJAX call returns 0

Note that the action should be inside the data key. In your post request there is no key named as action therefore, the callback function is never being called. Consider this example:- jQuery.ajax({ type:”POST”, url: “/wp-admin/admin-ajax.php”, data: { action: “my_test_action”, form_data : newFormChange }, success: function (data) { console.log(data); } }); Also Note: Never use … Read more