
/**
* Enable the use of short codes in text widgets.
*/
add_filter('widget_text', 'do_shortcode');
add_filter('manage_elementor_library_posts_columns', 'prefix_edit_elementor_library_posts_columns');
function prefix_edit_elementor_library_posts_columns($columns)
{
$columns['prefix_shortcode_column'] = esc_html__('Shortcode', 'text_domain');
return $columns;
}
add_action('manage_elementor_library_posts_custom_column', 'prefix_add_elementor_library_columns', 10, 2);
function prefix_add_elementor_library_columns($column, $post_id)
{
switch ($column) {
case 'prefix_shortcode_column':
echo '<input type="text" class="widefat" value=\'[elementor-template id="' . $post_id . '"]\' readonly>';
break;
}
}
add_shortcode('elementor-template', 'prefix_add_elementor');
function prefix_add_elementor($atts)
{
if (!class_exists('Elementor\Plugin')) {
return false;
}
if (!isset($atts['id']) || empty($atts['id'])) {
return false;
}
$post_id = $atts['id'];
$response = Elementor\Plugin::instance()->frontend->get_builder_content_for_display($post_id);
return $response;
}