1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Fields
  5. Media Field

Media Field

Arguments

NameTypeDefaultDescription
idstring A unique ID. This ID will be used to get the value
typestringmediaType of the field
titlestring Title of the field
defaultarray Default value from database, if the option doesn’t exist
subtitlestring Subtitle to display below the title.
descstring Description to display after the field
helpstring Text to display on right-corner (as hover/popup) of the field
classstring Extra CSS classes (space separated) to append to the field
beforestring Content to display before the field
afterstring Content to display after the field
dependencyarray Define field visibility depending on other field value
attributesarray Extra HTML attributes to append to the field
sanitizestring Callback function for sanitizing value
validatestring Callback function for validating value
EXTRAS   
urlbooltrueFlag to display url of the field
previewbooltrueFlag to display preview of the field
libraryarray|stringallTell the modal to show specific formats. for ( image or video or both )
placeholderstringNo media selectedThe placeholder to be displayed when nothing is selected
preview_sizestringthumbnailThe image size to use in preview (thumbnail or full)
button_titlestringUploadText to display on the upload button
remove_titlestringRemoveText to display on the remove button

Default Arguments

NameTypeDescription
urlstringString representing the default URL of the attachment.
idnumberNumberic representing the default attachment ID
widthnumberString representing the default image width value
heightnumberString representing the default image height value
thumbnailstringString representing the default image thumbnail
altstringString representing the default alt value
titlestringString representing the default title value
descriptionstringString representing the default description value

Simple Media Field Example

array(
  'id' => 'example-media',
  'type' => 'media',
  'title' => 'Media',
),

Media Field Example without Preview

array(
  'id' => 'example-media',
  'type' => 'media',
  'title' => 'Media',
  'preview' => false,
),

Media Field Example using only Image Formats

array(
  'id' => 'example-media',
  'type' => 'media',
  'title' => 'Media',
  'library' => 'image',
),

 

Was this article helpful to you? Yes No

How can we help?