Created
November 14, 2016 01:09
-
-
Save craigsimps/b75fb0528ae6ecd0ebd8ca37a3f36755 to your computer and use it in GitHub Desktop.
Return escaped ACF WYSIWYG field.
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
function return_escaped_acf_wysiwyg( $field, $post_id = false ) { | |
// If there's no post id defined, get id from current post. | |
if ( ! $post_id ) { | |
$post_id = (int) get_the_ID(); | |
} | |
// Get the custom field. | |
$content = get_post_meta( $post_id, $field, true ); | |
// Check wp_embed is enabled. | |
if ( isset( $GLOBALS['wp_embed'] ) ) { | |
// If the content contains something we can oEmbed, do it. | |
$content = $GLOBALS['wp_embed']->autoembed( $content ); | |
} | |
// Return the escaped output, allowing shortcodes to run. | |
return do_shortcode( wp_kses_post( $content ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment