【问题标题】:Hook into elementor widget?连接到 elementor 小部件?
【发布时间】:2018-12-08 04:55:20
【问题描述】:

我正在尝试找到一个钩子,可以让我将自己的代码添加到现有的 elementor 小部件中。例如,他们有“帖子小部件”,可让您根据设置的条件/类别显示帖子列表。

我想将我自己的代码添加到这个“块”中,但找不到任何特定的挂钩来挂钩到现有小部件(特别是帖子小部件)

任何帮助将不胜感激。有这个钩子吗?如果不是,我的下一个最佳选择是什么?

谢谢!

【问题讨论】:

标签: elementor


【解决方案1】:

这取决于您想要实现的目标,但一般都有钩子。

我不确定帖子小部件,但我可以向您展示一些一般性的示例。

如果您想向小部件添加控件,请使用此功能(您可以在其文档 https://developers.elementor.com/add-controls-to-widgets/ 中找到有关名称和内容的其他信息)

add_action( 'elementor/element/heading/section_title/before_section_end', function( $element, $args ) {
    $element->add_control( 'title_color',
        [
            'label' => 'Color' ,
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'red',
            'options' => [
                'red' => 'Red',
                'blue' => 'Blue',
            ],
            'section' => 'section_title',
            'tab' => 'content',
        ]
    );
}, 10, 2);

示例中的小部件是标题。您可以通过检查编辑器或插件目录中的块来查找注册名称

如果你想改变一个小部件的渲染内容,你可以使用这个

add_action( 'elementor/widget/render_content', function( $content, $widget ){ // $content (string) = the rendered content of the widget; widget = the data object 
    if ($widget->get_name() === 'heading') { // your targeted widget
        $settings = $widget->get_settings(); // every that is stored in this method. Titles, captions, margins and so on. Usually this is all you need
        // eg if you simply want to wrap your widgets content you can do something like this
        $content .= '<div class="i-am-a-wrapper">'.$content.'</div>';
    }
    return $content;
}, 10, 2 );

我希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-03
    • 2020-09-08
    • 2020-11-20
    • 2022-08-04
    • 1970-01-01
    • 2021-03-13
    • 2020-05-19
    • 2013-10-31
    相关资源
    最近更新 更多