# Shortcode for ACF Options Page Fields

> Adds an [acf_option name="phone"] shortcode that prints a value from an ACF options page anywhere, such as a phone number or address in widgets and footers.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: acf, options-page, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/acf-option-field-shortcode/

## Code

```php
add_shortcode( 'acf_option', function ( $atts ) {
    $atts = shortcode_atts( array( 'name' => '', 'default' => '' ), $atts, 'acf_option' );
    $name = sanitize_key( $atts['name'] );

    if ( '' === $name || ! function_exists( 'get_field' ) ) {
        return '';
    }

    $value = get_field( $name, 'option' );

    if ( is_array( $value ) ) {
        $value = isset( $value['label'] ) ? $value['label'] : implode( ', ', array_filter( $value, 'is_scalar' ) );
    }

    if ( is_bool( $value ) ) {
        $value = $value ? 'Yes' : 'No';
    }

    return esc_html( '' === (string) $value ? $atts['default'] : (string) $value );
} );
```

## Notes

Text, number, email, URL, select and true/false fields work. Use default="..." for a fallback.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Shortcode for ACF Options Page Fields" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
