我试图找到一个钩子,让我把自己的代码添加到现有的Elementor部件中。例如,他们有一个 "post widget",可以让你根据你设置的条件类别显示一个帖子列表。
我想把我自己的代码添加到这个 "块 "中,但无法找到任何特定的钩子来钩入现有的widget(特别是post widget)。
如果有任何帮助,将非常感谢。是否有一个钩子?如果没有,我的下一个最佳选择是什么?
谢谢!我想找一个钩子,让我把自己的代码添加到现有的Elementor widget中。
这取决于你想实现什么,但一般来说,都有钩子。
我不确定post-widget,但我可以给你看一些一般的例子。
如果你想添加控件到一个小部件,使用这个(你可以在他们的文档中找到更多的名称和东西的信息)。https:/developers.elementor.com添加控件到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);
例子中的小部件是标题。你可以通过检查编辑器或插件目录下的区块来了解注册的名称。
如果你想改变一个widget的渲染内容,你可以使用这个方法
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 );
希望能帮到你:)