Skip to content
Custom fields for WordPress that are quick to build and quick to load. Get Pro

Media and content

File

Any file to download: a PDF, a document, a menu.

When to use it. One file: a PDF, a price list, a presentation.

What the editor sees. The name of the file, with Add file, Change and Remove.

The File field on an edit screen
The File field on an edit screen.
Name in files and code file
ugly_get() gives The ID, the URL or an array.
Behavior can be required; can share a line with other fields

Settings

Setting What it does Default
What the code receives What ugly_get() returns. The ID is the lightest: use it with wp_get_attachment_image(). Choices: {'value': 'id', 'label': 'The ID'}, {'value': 'url', 'label': 'The URL'}, {'value': 'array', 'label': 'All the details'}. id

In your theme

PHP
$file = ugly_get( 'brochure' );   // return format: array
if ( $file ) : ?>
	<a href="<?php echo esc_url( $file['url'] ); ?>" download>
		<?php echo esc_html( $file['filename'] ); ?>
	</a>
<?php endif;

Good to know

  • With What the code receives set to id, use wp_get_attachment_url( $id ).
  • It is a normal WordPress attachment.