Elementor Pro widgets and templates are an efficient way to add content on WordPress landing pages. Either you can add them manually or using WordPress hook. Using the Custom Query Filter, Query ID, you can further make the content dynamic by passing current page url, post id or other related information but that is additional that you can accomplish by adding Query ID in Elementor Pro widget.
If you are building a web portal with lot of landing pages, adding separate templates of Elementor Pro widgets on those landing pages is not a good idea. One better approach is adding Elementor Widgets on pages is by saving them as Elementor template, add the query id custom query filter to dynamically filter the records, such as category or tag, CPT, and add this container using short code or template or better still even use WordPress hook to include the container on any WordPress page dynamically by calling its shortcode.
Add Posts Widget Elementor Pro Templates on any child page using the_content hook
function pim_posts_on_child_page( $content ) {
global $post;
$parent_page_id = '5657';// put your parent page id here
if( in_array($parent_page_id, get_ancestors( $post->ID, 'page' ))) {
$level = count(get_post_ancestors( $post->ID )) + 1;
//Posts widget template will be added on 2nd and 3rd level pages excluding parent.
if( in_array($level, array(2, 3)) ){
//add Posts Widget Elementor Pro Templates block
$before_content .= do_shortcode('[elementor-template id="6359"]');
//add Posts Widget Elementor Pro Templates block
//$after_content .= do_shortcode('[elementor-template id="8373"]');
}
}
return $before_content . $content . $after_content;
}
add_filter( 'the_content', 'pim_posts_on_child_page', 10, 1 );
And here is the gist for adding Posts widget template on child pages of any parent page.
Hope that helps.




