Using values
Every field stores its value as a WordPress option, under the field name of the field. Read it with get_option(), anywhere in a theme or plugin.
$company = get_option( 'company_name' );
Not a developer? Show values in your content with the shortcode or a block.
Escape what you print
get_option() gives you the stored value. Escape it when you print it, like any other value:
<h1><?php echo esc_html( get_option( 'company_name' ) ); ?></h1>
<a href="<?php echo esc_url( get_option( 'company_website' ) ); ?>">Website</a>
<div class="intro">
<?php echo wp_kses_post( wpautop( get_option( 'intro_text' ) ) ); ?>
</div>
A default value
The second argument of get_option() is returned when the option does not exist yet:
echo esc_html( get_option( 'footer_text', 'All rights reserved.' ) );
An option is created when you save its menu in the editor, with the Default value of the field. So the fallback of get_option() is mostly for code that runs before that.
Examples
A checkbox
if ( get_option( 'show_banner' ) ) {
get_template_part( 'parts/banner' );
}
An image
echo wp_get_attachment_image( get_option( 'company_logo' ), 'medium', false, [
'class' => 'site-logo',
] );
A file
$url = wp_get_attachment_url( get_option( 'price_list' ) );
if ( $url ) {
printf( '<a href="%s">Download our price list</a>', esc_url( $url ) );
}
A date
Dates are stored as Y-m-d. Show them in the format of the site:
$date = get_option( 'event_date' );
if ( $date ) {
echo esc_html( wp_date( get_option( 'date_format' ), strtotime( $date ) ) );
}
A color as a CSS variable
add_action( 'wp_head', function () {
printf(
'<style>:root { --brand-color: %s; }</style>',
esc_attr( get_option( 'brand_color', '#3858e9' ) )
);
} );
An email address
$email = get_option( 'contact_email' );
printf( '<a href="mailto:%1$s">%2$s</a>', esc_attr( antispambot( $email ) ), esc_html( antispambot( $email ) ) );