Advertisement
fahimmurshed

Enable Shortcode for Elementor Page Builder "Saved Page Templates"

Jun 10th, 2023
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. // Add the custom columns to the book post type:
  2. add_filter( 'manage_elementor_library_posts_columns', 'elstem_set_custom_edit_book_columns' );
  3. function elstem_set_custom_edit_book_columns($columns) {
  4.     unset( $columns['author'] );
  5.     $columns['shortcode'] = __( 'Shortcode', 'shortcode-support-for-elementor-templates' );
  6.    
  7.  
  8.     return $columns;
  9. }
  10.  
  11. // Add the data to the custom columns for the book post type:
  12. add_action( 'manage_elementor_library_posts_custom_column' , 'elstem_custom_book_column', 10, 2 );
  13. function elstem_custom_book_column( $column, $post_id ) {
  14.     switch ( $column ) {
  15.  
  16.         case 'shortcode' :
  17.             echo '[el_shortcode id="'.$post_id.'"]';
  18.         break;
  19.  
  20.        
  21.  
  22.     }
  23. }
  24.  
  25. function elstem_the_shortcode_func( $atts ) {
  26.  
  27.  
  28.     ob_start();
  29.  
  30.     if (class_exists("\\Elementor\\Plugin")) {
  31.         $post_ID = $atts['id'];
  32.         $pluginElementor = \Elementor\Plugin::instance();
  33.         $contentElementor = $pluginElementor->frontend->get_builder_content($post_ID);
  34.  
  35.         echo apply_filters('the_content',$contentElementor);
  36.     }
  37.  
  38.     return ob_get_clean();
  39.  
  40. }
  41. add_shortcode( 'el_shortcode', 'elstem_the_shortcode_func' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement