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: Generate: Shortcodes: Media Library: Output

  • Create as Copy: If enabled, creates a copy of the image found in the Media Library as a new image, again stored in the Media Library.
    • This option is recommended to ensure that the image is as optimized as possible for SEO, as the below options can then be applied to the new copied image.
  • Image Size: The image size to output
  • Title: The title to assign to the copied image.
    • This can be a keyword.
    • This is ignored if Create as Copy = No. This is by design, to ensure the original Media Library Image’s Title (which might be relied upon by another Page) is not changed.
  • Alt Tag: The alt tag to assign to the image.
    • This can be a keyword.
    • When Create as Copy = No, this only affects the HTML image tag’s Alt Tag output.  This is by design, to ensure the original Media Library Image’s Alt Tag (which might be relied upon by another Page) is not changed.
  • Caption: The caption to assign to the image.
    • This can be a keyword.
    • This is ignored if Create as Copy = No. This is by design, to ensure the original Media Library Image’s Caption (which might be relied upon by another Page) is not changed.
  • Description: The description to assign to the image.
    • This can be a keyword.
    • This is ignored if Create as Copy = No. This is by design, to ensure the original Media Library Image’s Description (which might be relied upon by another Page) is not changed.
  • Filename: Define the filename to save the image as in the Media Library, excluding the extension.
    • This can be a keyword.
    • It’s useful to use a keyword and/or other terms to ensure that the filename is SEO friendly and related to your content.
    • This is ignored if Create as Copy = No. This is by design, to ensure the original Media Library Image’s Filename (which might be relied upon by another Page) is not changed.

EXIF

Page Generator Pro: Shortcode: Media Library: EXIF

The EXIF tab provides options to optionally write EXIF metadata to the image file.  This can be useful for Image SEO.

  • Latitude: The image’s location’s latitude.
  • Longitude: The image’s locations’ longitude.
  • Comments: Comments about the image.
  • Description: A description of the image.

If any value is blank and the imported image contains an existing value in the EXIF metadata, the existing value will be retained.

Any other EXIF metadata is retained.

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.