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.
Related Posts:
- How do I get the avatar URL instead of an HTML IMG tag when using get_avatar?
- Programmatically get images by URL and save in uploads folder
- Function to get URL of original uploaded image – full size
- WP 4.4. responsive images browser choosing the “wrong” one
- Remove images (files) that were generated when using add_image_size()
- How to reference a theme image in a stylesheet?
- Using Images in WordPress – Best Practices
- Mixed content warnings after changing site adress from HTTP to HTTPS
- Change html structure of all img tags in WordPress
- How to create thumbnails with a fixed width, so all of them will have the same width?
- Creating a rotating header /image slider using theme customization
- Adding HTML within an image title attribute
- Preview Image Path in Admin Section
- How do I delete thousands of unattached images?
- Why would image paths in wordpress suddenly change?
- How to remove link from an image in a post?
- Change html structure of all img tags in WordPress
- Limit author image size
- Remove the http protocol from images
- Setup A Default Featured Image
- How do i reference the theme path in pages for images?
- @wordpress/create-block image url in css
- What’s the best “insert all images” plugin?
- Any way to “combine” galleries or show multiple galleries as one?
- Add filename to attachment page url
- WordPress url image redirect to the homepage
- Broken urls with http site and https wp-admin
- A way to change image urls in post to cdn image url?
- How to change image url?
- Can I the caption shortcode to set caption to a data attribute, and with the image’s alignment intact?
- Remove image classes from post thumbnail output
- How can I make all post image uploads have data-width and data-height attributes automatically by default?
- Update image links in database
- Shortcode for a link and thumbnail
- media_sideload_image with rewritten urls?
- Photography Based Design – Multiple Images Per Post
- wp_upload_bits does not retrieve images that do not have an extension
- Get ALT attribute from title post (code not work)
- How to add an image to a custom url?
- images not showing after transfer
- Change media URL (images)
- Image LazyLoad plugin not loading jQuery dependancies with wp_enqueue_script in WP 3.3.1
- Redirect to another page using contact form 7? [closed]
- How to check for images before echo
- Remove height attribute from wp_get_attachment
- Images give 404 after changing default domain
- How to redirect homepage to actual URL?
- Need custom picture field for pages
- Clicks registering on Preview DNS site
- Is it possible to enable the ‘Link To’ field under ‘Attachment Display Settings’ for a Featured Image?
- Using a .pdf file as a page in wordpress
- Disable save as image on smartphones using all browsers ( chrome, firefox, ie, cm, opera )
- How to get image URL from media_sideload_image?
- Exclude image url from search query
- Redirect Image Url to a page via htaccess
- Apply nextgen-gallery lightbox effect [closed]
- How to replace post image url before posting using api?
- Hide or mask the url to an image
- Glitched page redirects to image
- i want to change URL of WordPress image or rewrite in runtime
- How to show a full page when someone links directly to an image on my site
- How to make image uploads default to full size?
- WordPress 404 Images – Images not found after deleted from media
- Alt attribute is not showing while the value is given in Media
- WooCommerce Variation Swatches and Photos – get attribute thumbnail
- Bypass wp_safe_remote_get()?
- Get “Image CSS Class” value from the Advanced Options section
- Unable to delete images in Media Library
- Dinamically modifying attributes of images on posts
- Which tools should I use for a gallery that uses an API and url for the path of the images?
- List sub pages with custom field content converting image ID to URL
- Change the image for a certain URL
- How to add multiple images in a page
- Only User Upload image Http Error
- Setting name of attachment URL
- Search and replace image urls in posts
- Protocol relative url not pulling up images on IE, FF, and OPERA
- Remove “align” attribute on images
- Upload button in metabox not working
- Saving a post, content filtering and user levels
- Slider do not add alt attribute. Cant get alt attribute from a media library!
- Broken image URL
- How do I mitigate the forward slash problem for URLs of images after a WP migration?
- How do I add a nested conditional within an echo – to use a default image if there isn’t one in the post?
- Images in sub-pages fail to load
- Why images are disappearing on WordPress web site?
- Img alt tag showing different value then entered
- get_post_custom: get image URL instead of image ID
- Featured Image not changing
- Are image addresses security relevant?
- Remote Image (from URL) as Media Library element
- Uploaded Media Images on Site
- WPALLIMPORT Exporting images from repeater field [closed]
- How to change image type for specific size?
- Getting custom size image URL
- WordPress is stripping the Alt tag’s quote marks from images where Alt is not set, but leaving the word ‘alt’ creating problems for ADA compliance
- Is There A Way Of Using the_post_thumbnail() to Pull In A Specific Image From The Media Library
- How to add featured image use HTML
- Correct color profile and saving? Thumbnail creation?
- WPML – Change media uploader language