This post was most recently updated on July 31st, 2024
WordPress provides a series of methods and global variables for getting the current url, template directory, plugin directory, includes directory, admin directory that saves us from using absolute paths. On the other hand JQuery under wordpress does not include such urls so we end up using absolute urls.
A workaround for this can be uding the following code:
/* Add scripts to admin and frontend */
add_action(‘admin_enqueue_scripts’, ‘scripts’);
add_action(‘wp_enqueue_scripts’, ‘scripts’);
function scripts() {
?>
Similarly you can add other urls. If added in pages directly or under other hooks it throws an “Headers already sent” error.