【发布时间】:2022-08-03 21:24:32
【问题描述】:
我正在寻找一种连接到 Elementor Posts Widget 的方法,以便在每个帖子的帖子标题下显示一个额外的 H2 标签。
然后,我将从单个帖子 ACF 字段中获取此 H2 值。
从我正在阅读的其他内容来看,有一些方法可以将输出的整个 HTML 作为字符串获取,但这需要大量的字符串替换,因此不是很有未来的证明。例如: Hook into elementor widget? https://developers.elementor.com/docs/hooks/render-widget-content/
如果我使用这样的代码,有没有办法在帖子标题之后挂钩?还是字符串替换是解决这个问题的最佳方法?
function change_heading_widget_content( $widget_content, $widget ) {
if ( \'posts\' === $widget->get_name() ) {
$settings = $widget->get_settings();
$post_id = \"Somehow get the post id (maybe look for in the $widget_content string per post?)\";
if ( ! empty( $settings[\'link\'][\'is_external\'] ) ) {
$widget_content .= \'<h2>\'. get_field(\"extra_heading\", $post_id) .\'<h2>\';
}
}
return $widget_content;
}
add_filter( \'elementor/widget/render_content\', \'change_heading_widget_content\', 10, 2 );
我感谢所有和任何帮助。 谢谢