Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created May 30, 2022 15:21
Show Gist options
  • Save gicolek/a7c0aad8353b509510da1acbea4f9e30 to your computer and use it in GitHub Desktop.
Save gicolek/a7c0aad8353b509510da1acbea4f9e30 to your computer and use it in GitHub Desktop.
Custom Elementor Widget functions.php
<?php
/**
* Custom Elementor Widgets
*/
class Custom_Elementor_Widgets {
protected static $instance = null;
public static function get_instance(){
if ( !isset( static::$instance ) ) {
static::$instance = new static;
}
return static::$instance;
}
protected function __construct(){
require_once( __DIR__ . DIRECTORY_SEPARATOR . 'elementor-widgets' . DIRECTORY_SEPARATOR . 'widget-custom-blog-loop.php' );
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] );
}
public function register_widgets(){
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor\My_Widget_Custom_Blog_Loop() );
}
}
add_action( 'init', 'custom_elementor_init' );
/**
* @hook init
* instantiate custom elementor widgets
*/
function custom_elementor_init(){
Custom_Elementor_Widgets::get_instance();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment