Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Matthew Spear
Matthew Spear
14,534 Points

What are the "/?ref=" appended on the end of the urls and how can I access / use them within WordPress?

I'm trying to build a site within WordPress and want a banner to show when referred from another site, the site appends a /?ref=producthunt onto the end of the url.

Are there any plugins that utilise them? Otherwise what is the easiest way to use them?

Thanks, Matt

1 Answer

Colin Marshall
Colin Marshall
32,861 Points

Those are called GET variables, which are variables appended to the URL.

In your theme files you can check to see if they are present when the page is loaded like this:

<?php

// put this in your header.php
$ref = $_GET['ref'];

// put this in your theme file where the banner will go
if ($ref == 'producthunt')  {
  // Insert Banner HTML
}

?>
Matthew Spear
Matthew Spear
14,534 Points

Brilliant - Thanks for your help!