Skip to content

Instantly share code, notes, and snippets.

@tmort
Last active January 22, 2019 21:44
Show Gist options
  • Save tmort/bdb338d362874cdaa0569f1e6ec7f23d to your computer and use it in GitHub Desktop.
Save tmort/bdb338d362874cdaa0569f1e6ec7f23d to your computer and use it in GitHub Desktop.
sf3_imgparam.php
<?php
/*
Plugin Name: SF3 Image Param Shortcode
Plugin URI: https://gist.github.com/tmort/bdb338d362874cdaa0569f1e6ec7f23d/edit
Description: Shortcode that allows parameters to be used in an image string.
Version: 0.1.0
Author: Tom
Author URI: https://sixfoot3.com
*/
add_shortcode('imgparam', 'imgparam_func');
function imgparam_func($atts, $content){
//[imgparam param="region" default="none-found" imgtype="jpg" imgpath="http://example.com/wp-content/uploads/2019/01/"]
$param = ($atts['param']) ? $atts['param'] : null;
$param = (isset($_GET[$param])) ? esc_attr($_GET[$param]) : $atts['default'];
if($param){
$imgurl = sprintf('%s%s.%s', $atts['imgpath'], $param, $atts['imgtype']);
return sprintf('<img src="%s" />', $imgurl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment