WordPress – Display an image using path from value set in cookie

I was wondering if anybody could help me please. I’ve been struggling with this for a couple of days and running out of steam. Google isn’t so great now either :/

I’m trying to display an image on my page where the source path is set in a cookie called ‘urlscreen’ which is set via query string val.

e.g.

https://www.website.com/?screenshot=https://www.website.com/image1.jpg
https://www.website.com/?screenshot=https://www.website.com/image2.jpg
https://www.website.com/?screenshot=https://www.website.com/image3.jpg

I added the following code to functions.php and the cookie gets set OK

$ckname2 = ‘urlscreen’;
$ckexpires2 = time() + 86400;
if (isset($_GET[‘screenshot’])) {
$ckvalue2 = $_GET[‘screenshot’];
setcookie($ckname2, $ckvalue2, $ckexpires2, ‘/’, COOKIE_DOMAIN);

Now I need to display the correct image on my epage.

I’ve tried creating a shortcode inside functions.php like so:

function get_my_cookie() {
echo $_COOKIE[‘urlscreen’];
}
add_shortcode(‘GMC’, ‘get_my_cookie’);

But I don’t know how to get this shortcode to be the source of an image on the page.

Obviously won’t work but I still tried it lolz.

Please can you help.

Cheers,

Read more here:: WordPress – Display an image using path from value set in cookie

Leave a Reply

Your email address will not be published. Required fields are marked *