# Shortcode for ACF Fields on the Post Author

> Adds an [author_field name="job_title"] shortcode that shows an ACF user field of the current post's author, for author boxes and bylines.

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

## Code

```php
// User fields that may be shown publicly.
$wpide_acf_public_user_fields = array( 'job_title', 'company', 'website', 'short_bio' );

add_shortcode( 'author_field', function ( $atts ) use ( $wpide_acf_public_user_fields ) {
    $atts = shortcode_atts( array( 'name' => '' ), $atts, 'author_field' );
    $name = sanitize_key( $atts['name'] );
    $post = get_post();

    if ( ! $post || ! in_array( $name, $wpide_acf_public_user_fields, true ) || ! function_exists( 'get_field' ) ) {
        return '';
    }

    $value = get_field( $name, 'user_' . (int) $post->post_author );

    return is_scalar( $value ) ? esc_html( (string) $value ) : '';
} );
```

## Notes

Only list fields that are safe to make public.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Shortcode for ACF Fields on the Post Author" 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/
