admin-ajax.php not working properly on subdomains

Don’t bother with the complicated cookie/ajax nonsense, use a REST API! We’ll use dependency injection and RESTful APIs to remove the cookies and simplify your AJAX code. First things first, lets turn this into a REST API: class Stuff { public function __construct() { add_action( ‘rest_api_init’, function () { register_rest_route( ‘soothsayer/v1’, ‘/current_rate/’, array( ‘methods’ => … Read more

detect referr page

If I understand you correctly, a) a user goes to any website, b) user clicks on “random article”, c) user is redirected to a random article, d) user loads that random article. Am I correct thus far? In that case, you’ll see the site from a) as your http referrer in d), because an HTTP … Read more

Implementation to count page visits of unique visitors based on a cookie

Here’s a minimum working example… (note: this is untested code.) add_action(‘init’, ‘custom_rsvp_handler’); function custom_rsvp_handler() { // for singular posts only // (could also check for event post type here) if (!is_singular()) {return;} // set cookie expiry length (eg. 28 days) $cookielength = time()+(60*60*24*28); // set a cookie key based on post ID global $post; $cookiekey … Read more

When ever wordpress home page refreshes the code is not reading the cookie as set anymore

You cannot use setcookie() after you’ve already started outputting stuff to the body (in this case your javascript-debugging, but possibly something else outside that function). Are you suppressing PHP warnings? It should complain with “Cannot send headers; headers already sent” and tell you where the output was started. To get rid of the problem regarding … Read more