【问题标题】:How to create php shortcode with dynamic link?如何使用动态链接创建 php 短代码?
【发布时间】:2021-06-20 14:17:55
【问题描述】:

我在创建 WordPress 短代码时遇到了一些问题,因此我可以将其放在我的 Elementor 页面模板下。

// Shortcode to output custom PHP in Elementor
function luxis_ics_endpoint( $atts ) {
    return '<a href="'.<?php echo get_feed_link("calendar"); ?>?id=<?php echo get_the_ID(); ?>"> Download .ics </a>';
        
}
add_shortcode( 'my_elementor_php_output', 'luxis_ics_endpoint');

所以返回,我不知道如何正确编写它,以便它可以获取那些 PHP 代码并在短代码中生成一个链接供我在前端使用。

任何建议将不胜感激!

【问题讨论】:

  • 如果你想将它作为“小部件”添加到 elementor,你需要编写一些额外的代码来告诉 elementor shordcode 及其设置。 elementor developers documentation 中提供了一些相关信息,可帮助您入门。

标签: php wordpress shortcode elementor


【解决方案1】:

您的代码看起来不错。在这种情况下,您需要 echo 函数而不是 return

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多