How to define WordPress ajaxurl which is only defined in the admin section.
add_action('wp_head', 'my_custom_plugin_ajaxurl_fix');
/**
* The ajaxurl is only defined in the admin section
*/
function my_custom_plugin_ajaxurl_fix() {
$url = admin_url('admin-ajax.php');
echo <<<EOF_BUFF
<script type="text/javascript">var ajaxurl = '$url';</script>
EOF_BUFF;
}
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer