Skip to content

Instantly share code, notes, and snippets.

@pingram3541
Created June 26, 2025 22:03
Show Gist options
  • Save pingram3541/2f0bda6dc80d88e5f0c585dfb4e7520d to your computer and use it in GitHub Desktop.
Save pingram3541/2f0bda6dc80d88e5f0c585dfb4e7520d to your computer and use it in GitHub Desktop.
Elementor Front End Re-Render Dynamic ACF field w/ Embedded Content
<?php
/**
* Filter - Frontend Render Tags
*
* Filters output render of Elementor text-editor widget w/ id of #acf_blog_post_content
*
* note: some Elementor processes are stripping out embed content that is normally allowed, such as Youtube videos
*/
function el_widget_before_render_content($widget_content, $widget){
if ( 'text-editor' === $widget->get_name() ) {
$settings = $widget->get_settings(); //contains all widget settings - read-only!
//checks if special id exists
if ( ! empty( $settings['_element_id'] ) && $settings['_element_id'] === 'acf_blog_post_content' ) {
// checks if we have dynamic content
if ( ! empty( $settings['__dynamic__'] ) ) {
$tag_text = $settings['__dynamic__'];
$tag_text = $tag_text['editor'];
// get parts, assign to variables
preg_match( '/id="(.*?(?="))"/', $tag_text, $tag_id_match );
preg_match( '/name="(.*?(?="))"/', $tag_text, $tag_name_match );
preg_match( '/settings="(.*?(?="]))/', $tag_text, $tag_settings_match );
// only if tag name/type = acf-text
if($tag_name_match[1] === 'acf-text'){
$tag_settings = json_decode( urldecode( $tag_settings_match[1] ), true );
// [ "key" => "field_67fda1203cbdf:blog_post_content" ]
// get acf key value, i.e. "field_67fda1203cbdf:blog_post_content"
$tag_key = $tag_settings["key"];
// Split the string by the colon
$tag_key = explode(':', $tag_key);
// Access the second part, ie. "blog_post_content"
$tag_key = $tag_key[1];
// get current post id, i.e. 94683
$current_post = get_post();
$post_id = $current_post->ID;
// now we get the field, fresh from the database
$field = get_field($tag_key, $post_id);
// let's make sure to process shortcodes too
$widget_content = do_shortcode( $field );
// replace the original $widget_content
return $widget_content;
}
}
}
}
// otherwise don't change anything
return $widget_content;
}
add_filter( 'elementor/widget/render_content', 'el_widget_before_render_content', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment