I'm looking for a way to connect the Elementor Posts Widget to display an additional H2 tag under the post title of each post.
I will then get this H2 value from the single post ACF field.
From other things I've read, there are ways to get the entire HTML of the output as a string, but this requires a lot of string replacement, so is not very future-proof. For example: Hook into elementor widget? https://developers.elementor.com/docs/hooks/render-widget-content/
If I use code like this, is there a way to hang it behind the post title? Or is string replacement the best way to solve this problem?
function change_heading_widget_content( $widget_content, $widget ) { if ( 'posts' === $widget->get_name() ) { $settings = $widget->get_settings(); $post_id = "Somehow get the post id (maybe look for in the $widget_content string per post?)"; if ( ! empty( $settings['link']['is_external'] ) ) { $widget_content .= '<h2>'. get_field("extra_heading", $post_id) .'<h2>'; } } return $widget_content; } add_filter( 'elementor/widget/render_content', 'change_heading_widget_content', 10, 2 );
I appreciate all the help. Thanks
If you dig into the Elementor Pro source code, you'll find a great tip: Dynamic Label -> ACF Module
Or try this: Dynamic Label -> ACF Module Rendering
Or just use
get_field('my-field')
instead of $post_id