I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see frontend requests go through “/wp-admin/”. No practical reason, just looks ugly IMO.)

So I’ve simply copied admin-ajax.php to the root dir at “/ajax.php”, adjusted the include paths and removed the WP_ADMIN constant definition. Seems to work like gangbusters (I can now just direct all my frontend AJAX requests to /ajax.php! And I can still use the normal wp_ajax hooks in my plugins!).

But is this safe? What might go wrong? Since this isn’t built into core, I assume there’s a good reason as to why not. But looking through the code, I can’t see any immediate problems.

You’re smart–tell me if this approach is crazy. Or if there’s a simpler method that I’m overlooking.

3

You could just use a RewriteRule to your .htaccess above the regular permalink rewrite rules:

RewriteRule ^ajax$ /wp-admin/admin-ajax.php [L]

Now send your AJAX requests to example.com/ajax, and never miss core changes to that file after upgrades.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *