How to pass on a value as parameter via url to another page

If you are working in a php file such as a template, you can use $_GET to extract the url variables. For example, if your url was mydomain.com/page?color=blue you would print it on screen by:

<?php echo $_GET['color']; ?>

This would print “blue”. So to make a conditional statement out of this, you could do:

<?php if( $_GET['color'] == 'blue' ) {
    echo '<img src="">';
} elseif( $_GET['color'] == 'red' ) {
    //do something else
}

Query strings are stored in the $_GET variable as an associative array. Now, if you want to do query strings in WordPress posts/pages, you need to create a function to read query strings via shortcode. It looked like you were doing this inside template files though so I will leave that solution out, unless you need it – then just let me know and I’ll edit this.