Last active
January 11, 2023 03:42
-
-
Save cliffordp/bef4f1c5054555991cccccb058796739 to your computer and use it in GitHub Desktop.
Advanced Custom Fields: support shortcodes in each field's Message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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