Newbie needs help with url and conditionals

Hi all

I am trying to include a JS script into the head of a secondary page, but not in any other page. The head is a global include.

I’ve tried many bits of code I have seen, nothing working.

Basically I need this:

if url(http://www.site.com/secondary_page) {
<script>This is a JS script</script>
}

Thanks

Hi, welcome to SitePoint. :slight_smile:

Check out $_SERVER[‘REQUEST_URI’].

Give the URL, http://www.example.org/products/view, it should contain, /products/view.

You can use this as your ‘switch’ to test against.


<?php if('/products/view' === $_SERVER['REQUEST_URI']): ?>
  <script type="text/javascript" src="assets/js/jquery/jquery-1.3.2.min.js"></script>
<?php endif; ?>

Hi Anthony

Thanks so much. That works perfectly and simpler then I thought.

THanks again for the speedy help!