这取决于您想要实现的目标,但一般都有钩子。
我不确定帖子小部件,但我可以向您展示一些一般性的示例。
如果您想向小部件添加控件,请使用此功能(您可以在其文档 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 );
我希望这会有所帮助:)