"Well that's easy, all you need is to add <?php echo get_home_url(); ?>
"But you're not in a PHP file, you're somewhere at the bottom of a specially linked JS file.
So the sneaky work around I've come up with works as follows:
- In the header.php of the template add the following code between the <head> tags:
<script type="text/javascript">
window.homeURL = "<?php echo get_home_url(); ?>";
</script> - When you need the site url you can access it like so:
location.href = window.homeURL;
Wait what? why attach the variable to window?
This ensures that no matter what context you are in, when you need the home url, it'll be available as window is available everywhere.
No comments:
Post a Comment