Skip to content

Instantly share code, notes, and snippets.

@craigsimps
Created November 14, 2016 01:09
Show Gist options
  • Save craigsimps/b75fb0528ae6ecd0ebd8ca37a3f36755 to your computer and use it in GitHub Desktop.
Save craigsimps/b75fb0528ae6ecd0ebd8ca37a3f36755 to your computer and use it in GitHub Desktop.
Return escaped ACF WYSIWYG field.
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