Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active January 11, 2023 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/bef4f1c5054555991cccccb058796739 to your computer and use it in GitHub Desktop.
Save cliffordp/bef4f1c5054555991cccccb058796739 to your computer and use it in GitHub Desktop.
Advanced Custom Fields: support shortcodes in each field's Message
<?php
/**
* ACF: render shortcodes in Message fields, except on the ACF settings screen.
*
* Does work on ACF Options pages, just not ACF Settings pages.
*
* @link https://gist.github.com/cliffordp/bef4f1c5054555991cccccb058796739 This snippet.
*/
add_filter( 'acf/load_field', function ( array $field ) {
global $plugin_page;
if (
! function_exists( 'acf_get_options_page' )
|| ! function_exists( 'acf_is_screen' )
|| ! is_admin()
|| empty( $field['type'] )
|| 'message' !== $field['type'] // Only for Message field types.
) {
return $field;
}
$options_page = acf_get_options_page( $plugin_page );
if (
! empty( $options_page )
|| ! acf_is_screen( 'acf-field-group' )
) {
if ( ! empty( $field['message'] ) ) {
$field['message'] = do_shortcode( $field['message'] );
}
}
return $field;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment