在elementor中更改小部件类别的顺序

时间:2020-02-10 12:29:08

标签: wordpress elementor

我想保留我的自定义类别。有人可以提供帮助。

查看我的代码

function add_elementor_widget_categories( $elements_manager ) {

    $elements_manager->add_category(
        'custom-widget',
        [
            'title' => __( 'Custom Widget', 'elementor' ),
            'icon' => 'fa fa-plug',
            'active' => true,
        ]
    );

}
add_action( 'elementor/elements/categories_registered', 'add_elementor_widget_categories' );

1 个答案:

答案 0 :(得分:0)

我用这样的东西

add_action( 'elementor/elements/categories_registered', function(\Elementor\Elements_Manager $elements_manager ) {

        //add our categories
        $category_prefix = 'aqb-';

        $elements_manager->add_category(
            $category_prefix . 'widgets',
            [
                'title' => 'Blah Blah',
                'icon' => 'fa fa-plug',
            ]
        );

        //hack into the private $categories member and reorder it so our stuff is at the top

        $reorder_cats = function() use($category_prefix){
            uksort($this->categories, function($keyOne, $keyTwo) use($category_prefix){
                if(substr($keyOne, 0, 4) == $category_prefix){
                    return -1;
                }
                if(substr($keyTwo, 0, 4) == $category_prefix){
                    return 1;
                }
                return 0;
            });

        };
        $reorder_cats->call($elements_manager);

    } );

基于此LIVE DEMO