Last active
April 6, 2022 10:40
-
-
Save mehedicsit/f24c518741f312771053d7abf631e5d0 to your computer and use it in GitHub Desktop.
elementor widget development initialize in theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Elementor; | |
class First_widget extends Widget_Base{ | |
public function get_name(){ | |
return "first-widget"; | |
} | |
public function get_title(){ | |
return "first Widget"; | |
} | |
public function get_icon() { | |
return "fa fa-twitter"; | |
} | |
public function get_categories() { | |
return [ 'general' ]; | |
} | |
} | |
Plugin::instance()->widgets_manager->register_widget_type( new First_widget ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ElementorCustomElement | |
{ | |
private static $instance = null; | |
public static function get_instance() | |
{ | |
if (!self::$instance) | |
self::$instance = new self; | |
return self::$instance; | |
} | |
public function init() | |
{ | |
add_action('elementor/widgets/widgets_registered', array($this, 'widgets_registered')); | |
} | |
public function widgets_registered() | |
{ | |
// We check if the Elementor plugin has been installed / activated. | |
if (defined('ELEMENTOR_PATH') && class_exists('Elementor\Widget_Base')) { | |
// We look for any theme overrides for this custom Elementor element. | |
// If no theme overrides are found we use the default one in this plugin. | |
$widget_file = get_template_directory() . '/lib/custom-elementor-widget.php'; | |
$template_file = locate_template($widget_file); | |
if (!$template_file || !is_readable($template_file)) { | |
$template_file = get_template_directory() . '/lib/custom-elementor-widget.php'; | |
} | |
if ($template_file && is_readable($template_file)) { | |
require_once $template_file; | |
} | |
} | |
} | |
} | |
ElementorCustomElement::get_instance()->init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment