Last active
December 8, 2023 10:47
-
-
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.
This file contains hidden or 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 | |
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