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

The PHP API

ugly_get() or ugly_show()?

They are the same pair as get_field() and the_field() of ACF.

1 minute to read Updated 1 week ago

ugly_get( 'title' ) ugly_show( 'title' )
What it does Gives the value as it was saved Prints the value, made safe
Use it to Compare it, loop over it, pass it to another function Show something in a template
Escaping None. You escape where it matters (esc_html, esc_url, esc_attr) Done for you, by the type of the field

What "safe" means in ugly_show()

It picks the right way for each kind of field, so you cannot forget it:

  • Text and text area keep their <br>, <strong> and the other tags that WordPress allows in a post, and lose what runs (<script>, onclick).
  • Addresses are escaped as addresses. Numbers as numbers.
  • Rich text is printed as the HTML WordPress would print for a post.
  • A table prints a <table>.
PHP
<h1><?php ugly_show( 'heading' ); ?></h1>

<?php if ( ugly_get( 'show_banner' ) ) : ?>
	<p><?php ugly_show( 'banner_text' ); ?></p>
<?php endif; ?>

What ugly_get() does not do

Text and text area fields keep what was typed, like ACF. So a <br> or a <strong> is still there, and echo ugly_get( 'title' ) prints it. A text area with Line breaks set already has its <br> or <p>. Nothing is escaped:

PHP
// In an attribute, escape it yourself.
<a href="<?php echo esc_url( ugly_get( 'website' ) ); ?>" title="<?php echo esc_attr( ugly_get( 'tooltip' ) ); ?>">

Did this article answer your question?