I have below code but wp says me:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘widget_categories’ not found or invalid function name in /home/deniztas/hekim.deniz-tasarim.site/wp-includes/class-wp-hook.php on line 287
So, why I cant add the function? What must I do?
<?php /** * Plugin Name: Hekim - Elementor Extension * Description: For Hekim Theme * Plugin URI: https://themeforest.net/user/helvatica * Version: 1.0.0 * Author: Helvatica Themes * Author URI: https://themeforest.net/user/helvatica * Text Domain: hekim-plugin-elementor-extension */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Main Elementor Test Extension Class * * The main class that initiates and runs the plugin. * * @since 1.0.0 */ final class Hekim_Elementor { /** * widget_categories * * Register new category for widgets. * * @since 1.2.0 * @access public */ public function widget_categories( $elements_manager ) { $elements_manager->add_category( 'hero-section', [ 'title' => esc_html__( 'Hero Sections for elemntor', 'megaaddons' ), 'icon' => 'fa fa-plug', ] ); } etc.etc. } add_action( 'elementor/elements/categories_registered', 'widget_categories' ); ?>
Advertisement
Answer
I think you want to add widget categories in Elementor to organize the widgets into groups (please be more clear about the goal you want to reach in your question next time). So if this is what you want to achieve, your plugin code should look like this:
<?php /** * Plugin Name: Hekim - Elementor Extension * Description: For Hekim Theme * Plugin URI: https://themeforest.net/user/helvatica * Version: 1.0.0 * Author: Helvatica Themes * Author URI: https://themeforest.net/user/helvatica * Text Domain: hekim-plugin-elementor-extension */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } function add_elementor_widget_categories( $elements_manager ) { $elements_manager->add_category( 'hero-section', [ 'title' => esc_html__( 'Hero Sections for elemntor', 'megaaddons' ), 'icon' => 'fa fa-plug', ] ); } add_action( 'elementor/elements/categories_registered', 'add_elementor_widget_categories' ); ?>
I found the correct structure in the documentation: https://developers.elementor.com/widget-categories/
You don’t need the class and all the other stuff, you can just hook in with add_action.
Hope this helps.