I'm looking for a way to hook into an Elementor Posts Widget to display an extra H2 tag under the posts title for each posts.
I would then get this H2 value from from the single posts ACF field.
From what I am reading else where there are ways to get the whole HTML of the output as string, but that requires a lot of string replace and so not very future proof. Eg: Hook into elementor widget? https://developers.elementor.com/docs/hooks/render-widget-content/
If I am using a code like this is there a way to hook this after the Post title? or is string replace the best way to approach this?
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 and any help. Thanks