为什么不会出现快速代码出现在Elementor HTML小部件内?

发布于 2025-01-28 21:22:19 字数 619 浏览 3 评论 0原文

我在Elementor的HTML小部件内有一些自定义的HTML,CSS和JS。在某个时候,我不得不用我在里面制作的短码插入一个DIV标签。快速代码在Elementor的短代码小部件中显示罚款,但在Elementor的HTML小部件中不显示。为什么会发生这种情况?

这是我在functions.php 中的短代码,除了Elementor的HTML窗口小部件外,它都可以使用

// Shortcode current username
function display_current_username () {
    $user = wp_get_current_user();
    $name = $user->user_firstname;
    
    // If the $name var is empty, return the user_firstname property.
    if ( $name === '' ) :
        return $user->display_name;
    endif;
    
    return $name;
}
add_shortcode('display_name', 'display_current_username');

I have some custom html, css and js inside elementor's html widget. At some point I had to insert a div tag with a shortcode made by me inside. The shortcode displays fine in elementor's shortcode widget, but does not display inside elementor's html widget. Why does this happen ?

This is the shortcode I have in functions.php - It works everywhere except in elementor's html widget

// Shortcode current username
function display_current_username () {
    $user = wp_get_current_user();
    $name = $user->user_firstname;
    
    // If the $name var is empty, return the user_firstname property.
    if ( $name === '' ) :
        return $user->display_name;
    endif;
    
    return $name;
}
add_shortcode('display_name', 'display_current_username');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初雪 2025-02-04 21:22:19

您可以使用Elementor的短码小部件,并在短码之前或之后使用HTML元素。它将很好地工作。但是在HTML小部件内部,它将无法使用,因为小部件不适合运行快速代码。

在快捷代码窗口内使用它 -

<div><b>[display_name]</b></div>

You can use the shortcode widget of Elementor and use the html elements before or after the shortcode. It will work perfectly. But inside the HTML widget it will not work as the widget is not for running shortcode.

Use it like this inside the shortcode widget -

<div><b>[display_name]</b></div>

傲娇萝莉攻 2025-02-04 21:22:19

根据Elementor帮助页面(上次更新:2024年3月7日):

“在HTML小部件内部,您可以嵌入HTML,CSS,短代码,还包括JS脚本。”

https://elementor.com/help/help/html-widget/

As per the Elementor help pages (Last Update: March 7, 2024):

"Inside the HTML Widget you can embed HTML, CSS, Shortcodes, and also include JS scripts."

https://elementor.com/help/html-widget/

I can confirm that it's actually working for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文