// Add custom widget for dynamic HTML for Elementor
add_action( 'elementor/widgets/widgets_registered', function( $widgets_manager ) {
/**
* Elementor_Alt_HTML_Widget Elementor Custom Widget.
*/
class Elementor_Alt_HTML_Widget extends \Elementor\Widget_Base {
/**
* Get widget name.
*/
public function get_name() {
return 'alt-html';
}
/**
* Get widget title.
*/
public function get_title() {
return __( 'Rivmedia Micro Data', 'plugin-name' );
}
/**
* Get widget icon.
*/
public function get_icon() {
return 'fa fa-code';
}
/**
* Get widget categories.
*/
public function get_categories() {
return [ 'general' ];
}
/**
* Register Alternate Text widget controls.
*/
protected function _register_controls() {
$this->start_controls_section(
'section_editor',
[
'label' => __( 'Rivmedia Micro Data', 'plugin-name' ),
]
);
$this->add_control(
'editor',
[
'label' => '',
'type' => \Elementor\Controls_Manager::TEXTAREA,
'dynamic' => [
'active' => true,
],
'default' => __( 'Place your code here.', 'plugin-name' ),
]
);
$this->end_controls_section();
}
/**
* Render Alternate Text widget output on the frontend.
*/
protected function render() {
$settings = $this->get_settings_for_display();
echo '<div class="rivmedia-microdata"><script type="application/ld+json">';
echo ( $settings['editor'] ) ? $settings['editor'] : '';
echo '</script></div>';
}
}
$widgets_manager->register_widget_type( new Elementor_Alt_HTML_Widget() );
} );