You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义Elementor Widget开发求助:Widget未显示在基础菜单

Fixing Your Custom Elementor Widget Not Showing Up in the Basic Menu

Hey there, let's tackle this Elementor widget issue together! The problem you're hitting is almost certainly because the hook elementor/widgets/widgets_registered you're using is deprecated in newer Elementor versions (3.0+). Those older tutorials often don't get updated to match the latest API changes, so let's swap in the correct code and get your widget showing up in the Basic menu.

Here's a Complete, Working Code Example

You can add this to your theme's functions.php file, or create a simple custom plugin for it (recommended for portability):

<?php
/**
 * Custom Elementor Basic Widget
 * Adds to Elementor's "Basic" category menu
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Block direct access to the file
}

// Define your widget class, extending Elementor's base widget
class My_Custom_Basic_Widget extends \Elementor\Widget_Base {

	// Unique ID for your widget
	public function get_name() {
		return 'my_custom_basic_widget';
	}

	// Widget title that appears in the menu
	public function get_title() {
		return esc_html__( 'My Custom Basic Widget', 'your-text-domain' );
	}

	// Icon for the widget menu (use any Elementor built-in icon)
	public function get_icon() {
		return 'eicon-star';
	}

	// THIS IS KEY: Assign widget to the "Basic" category
	public function get_categories() {
		return [ 'basic' ];
	}

	// Add settings/controls for the widget (optional but recommended)
	protected function register_controls() {
		$this->start_controls_section(
			'content_section',
			[
				'label' => esc_html__( 'Content', 'your-text-domain' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'widget_text',
			[
				'label' => esc_html__( 'Display Text', 'your-text-domain' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__( 'Hello from my custom widget!', 'your-text-domain' ),
			]
		);

		$this->end_controls_section();
	}

	// Frontend output of the widget
	protected function render() {
		$settings = $this->get_settings_for_display();
		?>
		<div class="custom-basic-widget">
			<p><?php echo esc_html( $settings['widget_text'] ); ?></p>
		</div>
		<?php
	}

	// Editor preview output (optional)
	protected function content_template() {
		?>
		<div class="custom-basic-widget">
			<p>{{{ settings.widget_text }}}</p>
		</div>
		<?php
	}
}

// Register the widget with Elementor using the correct hook
function register_my_custom_elementor_widget( $widgets_manager ) {
	$widgets_manager->register( new My_Custom_Basic_Widget() );
}
add_action( 'elementor/widgets/register', 'register_my_custom_elementor_widget' );

Key Fixes & Notes

  1. Updated Hook: We replaced the old elementor/widgets/widgets_registered with elementor/widgets/register, which is the current official hook for registering widgets in Elementor 3.0+. This hook passes the $widgets_manager object directly, which we use to register our widget.
  2. Category Assignment: The get_categories() method returns ['basic']—this ensures your widget shows up under the "Basic" menu in the Elementor editor.
  3. Proper Class Inheritance: Our widget class correctly extends \Elementor\Widget_Base, which is required for all Elementor widgets.
  4. Safety Checks: We added a check for ABSPATH to prevent direct access to the file, which is a best practice.

Debugging Steps If It Still Doesn't Show Up

  • Update Elementor: Make sure you're running the latest version of Elementor (3.0+). Older versions might not support the new hook.
  • Clear Elementor Cache: Go to Elementor → Tools → General and click "Clear Cache". Elementor sometimes caches widget lists.
  • Check for Syntax Errors: Enable WordPress debug mode (add define('WP_DEBUG', true); to your wp-config.php) to catch any syntax issues in your code.
  • Verify Elementor is Active: Double-check that Elementor is activated in your WordPress plugins menu.

内容的提问来源于stack exchange,提问作者wiloke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:27:40