Serve a different theme based on window size

You shouldn’t need to use a different theme. A good responsive theme should handle all sorts of device window sizes. The new default WP theme, Twenty Thirteen, is responsive mobile first and changes for different device screen sizes. http://wordpress.org/themes/twentythirteen

How to include php-generated javascript?

You can either not use wp_enqueue_script (which loads a JS file, where you won’t be able to use PHP) and instead simply print the script out on the wp_head or wp_footer hooks…. or you can use wp_localize_script() wp_enqueue_script( ‘some_handle’ ); $instance = // not sure how you are fetching this value $array = array( ‘thumbs’ … Read more

Using admin-ajax prevents regular php form submission

You can change the form action to admin-ajax.php?action=your_action and this will work, but it’s not best practice. The ajax submition should be added via javascript, not by changing the form action (also your js function should prevent the form from submiting normally, returning false – see here an example: http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/), and php handling of the … Read more

Localize script not working

You’re calling wp_localize_script before the action that enqueues the script has run. Move the localize into the enqueue action, after the script is enqueued. function my_scripts_method() { wp_enqueue_script( ‘ajax_script’, get_stylesheet_directory_uri() . ‘/js/ajax_script.js’, array( ‘jquery’ ) ); wp_localize_script(‘ajax_script’, ‘WPURLS’, array( ‘siteurl’ => get_option(‘siteurl’) )); } add_action( ‘wp_enqueue_scripts’, ‘my_scripts_method’ ); That said, you probably don’t want to … Read more

WordPress – admin-ajax.php returns 502 Bad Gateway [closed]

I had similar problem on wordpress site. add these lines inside http block of /etc/nginx/nginx.conf file. fastcgi_temp_file_write_size 10m; fastcgi_busy_buffers_size 512k; fastcgi_buffer_size 512k; fastcgi_buffers 16 512k; If it still not working also add this line client_max_body_size 50M;

Check ajax triggered from front-end or from dashboard

Ajax request in WordPress is always performed in admin side, so is_admin() returns always true. If you need to know where the ajax request come from you need to check where the script is executed, not where the script send the ajax request. For example: add_action(‘wp_enqueue_scripts’, ‘cyb_enqueue_scripts’); function cyb_enqueue_scripts() { //Register the script. wp_register_script(‘my-script’, get_stylesheet_directory_uri(). … Read more

Ajax insert or update data

I’m not entirely sure you want to call exit at the end of that function, since exit terminates all further PHP execution. This is likely the cause of your troubles. http://php.net/manual/en/function.exit.php That said, you can always test for the result of your queries by setting a variable to be the result, and then sending that … Read more

Nonce doesn’t validate in nopriv call

Use check_ajax_referer: https://codex.wordpress.org/Function_Reference/check_ajax_referer //Check nonce if ( !check_ajax_referer( ‘nonce-action-name’, ‘_wpnonce’, false ) ){ echo __(‘Ajax Security Check’, ‘yourtextdomain’); die(); }