Title: IF/ELSE without a loop
Last modified: August 22, 2016

---

# IF/ELSE without a loop

 *  Resolved [polyfade](https://wordpress.org/support/users/polyfade/)
 * (@polyfade)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/ifelse-without-a-loop/)
 * When there is an image, this displays just fine:
 *     ```
       <img class="img-background" src="[content type='text-blocks' name='map-banner' field image='background_image' return='url']" alt="">
       ```
   
 * However, if I write the following, and there is an image or not, the following
   doesn’t return anything:
 *     ```
       [if content type='text-blocks' name='map-banner' field image='background_image']
       <img class="img-background" src="[content type='text-blocks' name='map-banner' field image='background_image' return='url']" alt="">
       [/if]
       ```
   
 * Does the IF condition need to be inside a [loop] for it to work?
 * [https://wordpress.org/plugins/custom-content-shortcode/](https://wordpress.org/plugins/custom-content-shortcode/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * (@miyarakira)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/ifelse-without-a-loop/#post-5407283)
 * Hello, sorry for the late reply..
 * Yes, the [if] shortcode works outside the loop. I would make a few small differences
   in how the parameters are specified. Please try the following:
 *     ```
       [if type='text-blocks' name='map-banner' field='background_image']
         <img class="img-background" src="[content type='text-blocks' name='map-banner' image='background_image' return='url']" alt="">
       [/if]
       ```
   
 * Hopefully this will achieve what you’re looking for.

Viewing 1 replies (of 1 total)

The topic ‘IF/ELSE without a loop’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-content-shortcode_766976.svg)
 * [Custom Content Shortcode](https://wordpress.org/plugins/custom-content-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-content-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-content-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-content-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-content-shortcode/reviews/)

## Tags

 * [ACF](https://wordpress.org/support/topic-tag/acf/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)

 * 1 reply
 * 2 participants
 * Last reply from: [Eliot Akira](https://wordpress.org/support/users/miyarakira/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/ifelse-without-a-loop/#post-5407283)
 * Status: resolved