Skip to content

Instantly share code, notes, and snippets.

@craigsimps
Last active December 8, 2023 10:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigsimps/4f6aecd90551dc712448 to your computer and use it in GitHub Desktop.
Save craigsimps/4f6aecd90551dc712448 to your computer and use it in GitHub Desktop.
Escape the output of an ACF Wysiwyg field, but allow for oEmbed video and shortcodes.
<?php
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 kses'd content
$content = wp_kses_post( 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);
}
// echo the resulting content, allowing for shortcodes
return do_shortcode( $content );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment