开发者

Does WordPress expose a base URL in its JavaScript by default?

Usually when building sites I add something like this

var config = {
    basePath: '<?php echo BASE_PATH; ?>'
}

Simply so with my static JavaScript files I can do AJAX requests like

开发者_运维技巧var request = config.basePath + 'ajax/get-something';

Does WordPress have a similar variable available to its JavaScript files by default, assuming I add my own scripts at the bottom of all WordPress included stuff?

Thanks


In the admin, there's a global variable ajaxurl that gives you the WP Ajax Url. I don't know if there's one for the front end built in, but you can do something like this to do it:

add_action( 'wp_head', create_function( '', '// echo your content here' ) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜