Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created March 6, 2012 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/1986992 to your computer and use it in GitHub Desktop.
Save tollmanz/1986992 to your computer and use it in GitHub Desktop.
Happy AJAX on .com
/**
* Generates a domain-mapping safe URL on WordPress.com
* Core's ajaxurl uses admin_url() which returns *.wordpress.com which doesn't work for the front-end on domain-mapped sites.
* This works around that and generates the correct URL based on context.
*/
function admin_ajax_url( $path = '' ) {
if ( is_admin() )
$url = admin_url( 'admin-ajax.php' );
else
$url = home_url( 'wp-admin/admin-ajax.php' );
$url .= ltrim( $path, '/' );
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment