Generate: Shortcodes: Media Library Image

The Media Library Image shortcode inserts a dynamic, random image from your WordPress Media Library for each generated Page.

It’s different from the standard Add Media option that WordPress provides, because the shortcode parameters help build a dynamic query to fetch an image at random from the Media Library.  For example, you might only want to output a Media Library Image that contains certain text in the title or the alt tag.

In most TinyMCE instances, you’ll see an option to add the Media Library shortcode in the Visual Editor toolbar (camera and music note symbol):
Page Generator Pro: Generate: Shortcodes: TinyMCE Toolbar Button

A modal dialog will appear, with options split across two tabs:

Search Parameters

Page Generator Pro: Shortcode: Media Library: Search Parameters

  • Title: Fetch an image from the Media Library at random with a partial or full match to the given Title
  • Caption: Fetch an image from the Media Library at random with a partial or full match to the given Caption
  • Alt Text: Fetch an image from the Media Library at random with a partial or full match to the given Alt Text
  • Description: Fetch an image at random with a partial or full match to the given Description
  • Operator: Determines whether images should match all or any of the Title, Caption, Alt Text and Descriptions specified above.
  • Image IDs: Fetch an image at random from a comma separated list of Media Library Image ID(s)
  • Image ID Range: Fetch an image at random whose ID matches or is within the given range.

Output

Page Generator Pro: Shortcode: Media Library: Output

  • Image Size: The image size to output
  • Alt Tag: The alt tag to output with the image.  If blank, the alt tag from the image in the Media Library is used.

Click Insert to insert the shortcode.

A shortcode will then appear within the content:
[page-generator-pro-media-library title="title" caption="caption" alt="alt" description="description" ids="1,2,3" min_id="1" max_id="3" size="medium" alt_tag="alt tag to output"]

Parameter Accepted Value Description
title string or keyword Include images partially / fully matching the given Title.
caption string or keyword Include images partially / fully matching the given Caption
alt string or keyword Include images partially / fully matching the given Alt Text
description string or keyword Include images partially / fully matching the given Description
ids integer, comma separated integers or keyword Include images matching the given Image ID(s)
min_id integer or keyword Include images where their ID is greater than or equal to the given ID.
max_id integer or keyword Include images where their ID is less than or equal to the given ID.
size string Output the image at the given WordPress registered image size. Must use a value from WordPress’ get_intermediate_image_sizes() function.
alt_tag string The alt tag to output with the image.  If blank, the alt tag from the image in the Media Library is used.