Change theme based on window size

Your code actually works for me and it is changing the theme according to the current width. But I think you should need some tweaking something like below: For your JavaScript: var $ = jQuery; $(document).ready(function() { var windowWidth = $(window).width(); var windowHeight = $(window).height(); $.ajax( { type: “POST”, url: “http://example.com/wp-admin/admin-ajax.php”, // Must use absolute … Read more

Nonces and Ajax request to REST API and verification

For restricting access to your REST API endpoint, you can use the permission_callback parameter like so: register_rest_route( ‘rw-user/v1’, ‘/log-out’, array( ‘methods’ => ‘POST’, ‘callback’ => ‘ajax_logout’, ‘permission_callback’ => function () { return current_user_can( ‘read’ ); }, ) ); And that will require the current user to be logged into WordPress and also the REST API … Read more

Load page content with AJAX using Fancybox?

Here it is. Google use no JS and there is no fancy. Also links can be used with no get, just simple url: page.com/post-name/ On single page: <?php $apost = $_GET[“type”]; preg_replace(‘/_/’, ‘html’, preg_replace(‘/%/’, ‘html’, htmlentities(mysql_real_escape_string($apost)))); ?> <?php if($apost == ‘iframe’) { ?> <?php get_header(‘single’); ?> <?php if (have_posts()) : while (have_posts()) : the_post();?> <div … Read more

Run again current query via ajax but changing a var

You have to note that an ajax request is an entirely new http request, so the $query variable is defined in the page that send the ajax request but will be not set in the page that receive the request. That means that you have completely recreate the query and not change a param. That … Read more

How declare Ajax functions ussing SHORTINIT

Build the PHP script that will handle the ajax resquest and send the ajax request directly to that filet (not to wp-admin/admin-ajax.php). In that file, first define SHORTINIT, then load WordPress manually and finally handle the ajax request. define(‘SHORTINIT’,true); //IMPORTANT: Change with the correct path to wp-load.php in your installation require_once (‘../../../../wp-load.php’); //Load any WordPress … Read more

Insert Post using Ajax

What says the error log? Is that the complete content of form-process.php? When it is so, then the problem might be, that the function wp_insert_post() is not defined, because the WordPress core was not loaded. Therefore WordPress has an AJAX-API. Here’s an example on how to use that API on server side: add_action( ‘admin_ajax_your_form_action’, ‘wpse_126886_ajax_handler’ … Read more

Trying to load content of a post via AJAX

If your javascript action is named ajaxify, then these should be: add_action(‘wp_ajax_ajaxify’, ‘ajaxify’); // ajax for logged in users add_action(‘wp_ajax_nopriv_ajaxify’, ‘ajaxify’); // ajax for not logged in users the actions you hook are a concatenation of wp_ajax_(nopriv_) and your action name. the function that’s hooked to that action can have any name, so it could … Read more